Java Utililty Methods Json to Object

List of utility methods to do Json to Object

Description

The list of methods to do Json to Object are organized into topic(s).

Method

Tdecode(String httpMessageBody, Class objectClass)
decode
try {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readValue(httpMessageBody, objectClass);
} catch (IOException e) {
    throw new IllegalArgumentException("httpMessageBody is not a valid JSON", e);
JsonNodedecode(String input)
decode
return decode(input, false);
Tdecode(String json, Class clazz)
decode
try {
    return mapper.readValue(json, clazz);
} catch (IOException e) {
    throw new RuntimeException("Can't serialize object", e);
Tdecode(String json, Class clazz)
json decode
try {
    return new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).readValue(json,
            clazz);
} catch (IOException e) {
    throw new IllegalStateException(e);
StringdecodeCommandAsJson(final BsonInput bsonInput)
decode Command As Json
bsonInput.readInt32(); 
bsonInput.readInt32(); 
bsonInput.readInt32(); 
bsonInput.readInt32(); 
bsonInput.readInt32(); 
bsonInput.readCString(); 
bsonInput.readInt32(); 
bsonInput.readInt32(); 
...
Tdeserialize(JsonReader reader, Class type)
deserialize
T t = GSON.fromJson(reader, type);
reader.close();
return t;
Tdeserialize(String json, Class clazz)
deserialize
try {
    return objectMapper.readValue(json, clazz);
} catch (IOException e) {
    e.printStackTrace();
    return null;
Tdeserialize(String json, Class targetType)
deserialize
try {
    return objectMapper.readValue(json, targetType);
} catch (IOException e) {
    throw new IllegalStateException("Failed to convert json to object", e);
Tdeserialize(String jsonData, Class typeOfT)
deserialize
if (jsonData == null) {
    return null;
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(jsonData, typeOfT);
TdeserializeFromDataNode(JsonParser jp, DeserializationContext ctxt, String propertyName, TypeReference typeReference)
deserialize From Data Node
if (jp.hasCurrentToken() && jp.getCurrentToken().equals(JsonToken.START_OBJECT)) {
    JsonNode dataNode = jp.readValueAs(JsonNode.class);
    if (dataNode.has(propertyName)) {
        return OBJECT_MAPPER.reader(typeReference).<T>readValue(dataNode.get(propertyName));
    return null;
throw ctxt.mappingException("Expected JSON object");
...