
com.eatthepath.json.JsonDeserializer Maven / Gradle / Ivy
package com.eatthepath.json;
import java.io.StringReader;
import java.util.Map;
/**
* An extremely simple JSON object deserializer that interprets JSON objects as Java primitives. JSON types are
* mapped to Java types as follows:
*
*
* Mapping of JSON types to Java types
*
*
*
* JSON type
* Java type
*
*
*
*
*
* string
* {@link String}
*
*
*
* number
* {@link Number} ({@link Long} or {@link Double})
*
*
*
* object
* {@link Map}<{@link String}, {@link Object}>
*
*
*
* array
* {@link java.util.List}<{@link Object}>
*
*
*
* boolean
* boolean
*
*
*
* null
* null
*
*
*
*
* {@code JsonDeserializer} instances are not thread-safe; only one thread may safely use a single
* deserializer at a time.
*
* @author Jon Chambers
*
* @since 0.14.0
*/
public class JsonDeserializer {
private final JsonParser jsonParser = new JsonParser(new StringReader(""));
/**
* Parses a JSON string as a JSON object.
*
* @param jsonString the JSON string to be parsed
*
* @return a Java representation of the JSON-encoded object
*
* @throws ParseException if the given {@code jsonString} does not represent a valid JSON object
*/
public Map parseJsonObject(final String jsonString) throws ParseException {
jsonParser.ReInit(new StringReader(jsonString));
return jsonParser.object();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy