Posted In: JSON

Are escaping special characters in JSON string required?

  Following tests with various libraries confirms that JSON library will handle special characters and there is no need to use StringEscapeUtilities.escapeHtml, StringEscapeUtilities.escapeXml or java.net.URLEncoder   1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using com.jsoniter.output.JsonStream from json iterator library […]

Read More

Tags: , , , , ,

by , on February 22nd, 2017

Posted In: JSON

How to parse JSON to POJO in Java

  This example uses general JSONObject or Any object provided by library. To parse JSON to your own application POJO refere this.   1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using JsonIterator from json iterator library   6. Using […]

Read More

Tags: , , , , ,

by , on February 22nd, 2017

Posted In: JSON

How to parse JSON in Java – Without POJO

  This example uses general JSONObject or Any object provided by library. To parse JSON to your own application POJO refer how-to-parse-json-to-pojo-in-java   1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using JsonIterator from json iterator library   6. Using […]

Read More

Tags: , , , , ,

by , on February 22nd, 2017

Posted In: JSON

How to convert ArrayList to JSON object in Java

  1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using com.jsoniter.output.JsonStream from json iterator library   6. Using net.sf.json.JSONArrayfrom net.sf.json-lib library   7. Using javax.json.JsonArray, javax.json.JsonArrayBuilder from javax.json library   8. Using org.json.JSONArray from org.json library   9. Output [“val1″,”val2″,”val3″,”val4″,”val5”] […]

Read More

Tags: , , , , , , , , ,

by , on February 22nd, 2017

Posted In: JSON

How to convert hashmap to JSON object in Java

  1. Example will use following Test data   2. Using GSON   3. Using Jackson 2X   4. Using Jackson 1X   5. Using com.jsoniter.output.JsonStream from json iterator library   6. Using net.sf.json.JSONObject from net.sf.json-lib library   7. Using javax.json.JsonObject, javax.json.JsonObjectBuilder from javax.json library   8. Using org.json.JSONObject from org.json library   9. Output […]

Read More

Tags: , , , , , , , , ,

by , on February 21st, 2017

Posted In: JSON, jsoniter

Generate Java POJO from JSON or JSON schema – Annotation style – None – jsoniter

  We created POJOs from JSON in previous example generate-java-pojo-from-json-or-json-schema. Let us go through some options that we have on http://www.jsonschema2pojo.org/   Annotation style – None. Let use jsoniter library to populate this POJO Maven for jsoniter   1. Example will use following sample JSON     2. Following POJO will be generated     […]

Read More

Tags: ,

by , on February 21st, 2017

Posted In: Jackson 2X, JSON

Generate Json Schema from POJO – Jackson 2X

  1. Example is using Address POJO with multiple fields.   2. Use com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator class to get schema from POJO class       3. Schema generated    

Read More

Tags: ,

by , on February 21st, 2017

Posted In: Jackson 1X, JSON

Generate Json Schema from POJO – Jackson 1X

  1. Example is using Address POJO with multiple fields.   2. Use org.codehaus.jackson.schema.JsonSchema class to get schema from POJO class     3. Schema generated    

Read More

Tags: ,

by , on February 21st, 2017

Posted In: GSON, JSON

Generate Java POJO from JSON or JSON schema – Annotation style – GSON

  We created POJOs from JSON in previous example generate-java-pojo-from-json-or-json-schema. Let us go through some options that we have on http://www.jsonschema2pojo.org/   Annotation style – GSON 1. Example will use following sample JSON     2. Following POJO will be generated     3. Use Gson library to parse JSON and populate POJOs     […]

Read More

Tags: ,

by , on February 20th, 2017

Posted In: Jackson 2X, JSON

Generate Java POJO from JSON or JSON schema – Annotation style – Jackson 2.x

  We created POJOs from JSON in previous example generate-java-pojo-from-json-or-json-schema. Let us go through some options that we have on http://www.jsonschema2pojo.org/   Annotation style – Jackson 2.x This will add annotations like @JsonProperty, @JsonPropertyOrder, @JsonInclude to your POJOs. Jackson will use these annotations for mapping fields to JSON. It has side effect and cause production […]

Read More

Tags: , , , , , ,

by , on February 20th, 2017

  • Categories