@Override public Character deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); int value; if (t == JsonToken.VALUE_NUMBER_INT) { // ok iff ascii value value = jp.getIntValue(); if (value >= 0 && value <= 0xFFFF) { return Character.valueOf((char) value); } } else if (t == JsonToken.VALUE_STRING) { // this is the usual type // But does it have to be exactly one char? String text = jp.getText(); if (text.length() == 1) { return Character.valueOf(text.charAt(0)); } // actually, empty should become null? if (text.length() == 0) { return (Character) getEmptyValue(); } } throw ctxt.mappingException(_valueClass, t); } }
@Override public Character deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); int value; if (t == JsonToken.VALUE_NUMBER_INT) { // ok iff ascii value value = jp.getIntValue(); if (value >= 0 && value <= 0xFFFF) { return Character.valueOf((char) value); } } else if (t == JsonToken.VALUE_STRING) { // this is the usual type // But does it have to be exactly one char? String text = jp.getText(); if (text.length() == 1) { return Character.valueOf(text.charAt(0)); } // actually, empty should become null? if (text.length() == 0) { return (Character) getEmptyValue(); } } throw ctxt.mappingException(_valueClass, t); } }
return (Character) getEmptyValue();
return (Character) getEmptyValue();
@Override public Character deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { switch (p.getCurrentTokenId()) { case JsonTokenId.ID_NUMBER_INT: // ok iff ascii value int value = p.getIntValue(); if (value >= 0 && value <= 0xFFFF) { return Character.valueOf((char) value); } break; case JsonTokenId.ID_STRING: // this is the usual type // But does it have to be exactly one char? String text = p.getText(); if (text.length() == 1) { return Character.valueOf(text.charAt(0)); } // actually, empty should become null? if (text.length() == 0) { return (Character) getEmptyValue(ctxt); } break; case JsonTokenId.ID_START_ARRAY: return _deserializeFromArray(p, ctxt); default: } return (Character) ctxt.handleUnexpectedToken(_valueClass, p); } }