Figured out what the problem was. Needed to extract the jsonobject instead of getting the string. Here was the line that fixed the issue:

UserIdentifier userIdentifier = gson.fromJson(jsonResponse.getJSONObject("userIdentifier").toString(), UserIdentifier.class);
Answer from Richard on Stack Overflow
🌐
Medium
medium.com › @benpourian › how-to-create-a-java-object-from-a-json-object-c47c08b030c5
How to create a Java Object from a JSON object | by Benjamin Pourian | Medium
October 25, 2018 - ./json-to-java-object/src/main/java/com/jtjo/model/SimplePojo.java; To best demonstrate the workings of the gson library I have written a bunch of unit tests using JUNIT5 . Now that we have our SimplePojo class we can create a bunch of objects using a JSON object; I have a class in my test directory called SimplePojoTest and this is the outline of the class as follows; package com.jtjo.model;import com.google.gson.Gson; import com.google.gson.JsonObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test;@DisplayName("SimplePojo
Discussions

How to convert a Java Object to JsonObject type of couch base?
The example i found at “http://docs.couchbase.com/developer/java-2.0/documents-bulk.html” is going though each property in java class and adding it to JsonObject. is there a way that we can convert a Java object into JsonObject without traversing through all properties manually and adding ... More on couchbase.com
🌐 couchbase.com
0
0
June 24, 2015
Convert Java object to JSON without external library
Converting arbitrary objects to JSON isn't particularly easy, especially when there are full solutions already available. Personally, I use Gson, which is pretty easy to use. If the no external libraries is a HARD requirement, then your only choice would be to use reflection to get the names and values of the fields of the object to build the JSON string. You might have recursion problems if there are nested objects that create a circular loop, which complicates things. If you only have to serialize specific classes, then it would probably be easier to essentially hardcode the JSON string generation, and just call the appropriately getters to build the string. Basically, if it's only a few specific classes then you can write your own, if it's any arbitrary object then I highly recommend using a library, but if no libraries then I guess you could try homerolling your own JSON serializer with reflection. More on reddit.com
🌐 r/javahelp
12
May 1, 2020
Converting Json to Java object
Jackson is a library that people use to deserialize json to Java. More on reddit.com
🌐 r/javahelp
10
7
December 13, 2022
How to convert object to json in controller?
Spring will do it for you. Just create a separate controller and annotate the class with @RestController. Then just return your object or list of objects in your controller method. Spring will automatically use Jackson to serialize it to JSON. More on reddit.com
🌐 r/SpringBoot
6
6
September 2, 2022
🌐
Stack Abuse
stackabuse.com › how-to-convert-json-object-to-java-object-with-jackson
How to Convert JSON Object to Java Object with Jackson
February 27, 2023 - To convert a JSON object into a Java object, you'll use the readValue() method of the ObjectMapper instance, which deserializes it into the provided class reference:
🌐
Mkyong
mkyong.com › home › java › convert java objects to json with jackson
Convert Java Objects to JSON with Jackson - Mkyong.com
April 24, 2024 - package com.mkyong.json.jackson.tips; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.mkyong.json.model.Person; public class ConvertObjectToJsonExample2 { public static void main(String[] args) { String json = "{\"name\": \"mkyong\", \"age\": 20}"; ObjectMapper om = new ObjectMapper(); try { // covert JSON to Java object Person person = om.readValue(json, Person.class); // output: Person{name='mkyong', age=20} System.out.println(person); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } } ... This example uses Jackson to convert a Java object Person to a JSON string and write it in a file named person.json.
🌐
Json2CSharp
json2csharp.com › code-converters › json-to-pojo
Convert JSON to POJO Objects in Java Online
Here's how you can convert your JSON string to JAVA objects, we will be using the converter and external libraries like Jackson objectmapper to parse our object.
Find elsewhere
🌐
Couchbase
couchbase.com › java sdk
How to convert a Java Object to JsonObject type of couch base? - Java SDK - Couchbase Forums
June 24, 2015 - The example i found at “http://docs.couchbase.com/developer/java-2.0/documents-bulk.html” is going though each property in java class and adding it to JsonObject. is there a way that we can convert a Java object into JsonObject without traversing through all properties manually and adding ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-json-array-object-to-java-object
How to Convert JSON Array Object to Java Object? - GeeksforGeeks
July 23, 2025 - Below are the steps and implementation to convert JSON Array object to Java object using Jackson library.
🌐
Reddit
reddit.com › r/javahelp › convert java object to json without external library
r/javahelp on Reddit: Convert Java object to JSON without external library
May 1, 2020 -

I feel like an idiot, I mean, I have been programming for a few years, mostly C# and Java, but all the REST apis I made was built with .NET, so I had no need for it.

Well, I can't find how to convert a Java object to a JSON WITHOUT the need of an external library, anyone?

🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › Converting-JSON-to-Java-Object-Array › m-p › 153155
Solved: Converting JSON to Java Object Array - Cloudera Community - 153155
February 1, 2017 - Error: Can not deserialize instance of java.lang.Object[] out of START_OBJECT token at [Source: {"f1":1,"f2":"abc"}; line: 1, column: 1] ... import org.json.JSONObject; public class JSONParser { public static void main(String[] args) { String jsonStr = "{\"field1\":1,\"field2\":\"abc\"}"; JSONObject json = new JSONObject(jsonStr); Person person = new Person(); person.setKey(json.getInt("field1")); person.setValue(json.getString("field2")); System.out.println(person.toString()); } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-java-object-to-json-string-using-gson
Convert Java Object to Json String using GSON - GeeksforGeeks
July 11, 2025 - GSON: It is an open-source Java library which is used to serialize and deserialize Java objects to JSON.
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-java-object-to-json-using-jackson-library
How to convert Java object to JSON using Jackson library?
Tree Model - prepares a in-memory tree representation of the JSON document. ObjectMapper build tree of JsonNode nodes. It is most flexible approach. It is analogus to DOM parser for XML. Data Binding - converts JSON to and from POJO (Plain Old Java Object) using property accessor or using annotations.
🌐
Quora
quora.com › How-do-I-convert-a-nested-JSON-string-to-a-Java-object
How to convert a nested JSON string to a Java object - Quora
Answer: The pedestrian way: 1. Convert the outermost JSON string into a Java object, using e.g. Gson or Jackson. 2. Access the nested JSON string inside the object created in step 1 and convert it into a Java object.
🌐
Educative
educative.io › answers › how-to-convert-a-java-object-to-json
How to convert a Java object to JSON
The Google GSON​ library is the most popular library used for converting Java objects to JSON.
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java | Baeldung
June 20, 2025 - A JSONArray is an ordered collection of values, resembling Java’s native Vector implementation: Values can be anything from a Number, String, Boolean, JSONArray, or JSONObject to even a JSONObject.NULL object
🌐
Quora
quora.com › What-is-the-reason-to-convert-Java-object-to-JSON-JSON-Object-or-vice-versa
What is the reason to convert Java object to JSON/ JSON Object or vice versa? - Quora
Light-weight: Compared to other formats like XML etc, JSON is quite light-weight. Object Oriented: JSON format can be easily converted into Java objects in an Object oriented manner.
🌐
Coderanch
coderanch.com › t › 524252 › frameworks › Converting-java-object-json
Converting java object to json (Struts forum at Coderanch)
However thats easy to solve as you have several options: 1) Use excludeProperties in the result configuration to tell it what properties to exclude 2) Create a new action that will handle your JSON call instead of using the same action and I'm sure there are other things you may be able to ...
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonObject.html
JsonObject (Java(TM) EE 7 Specification APIs)
JsonObject value = Json.createObjectBuilder() .add("firstName", "John") .add("lastName", "Smith") .add("age", 25) .add("address", Json.createObjectBuilder() .add("streetAddress", "21 2nd Street") .add("city", "New York") .add("state", "NY") .add("postalCode", "10021")) .add("phoneNumber", Json.createArrayBuilder() .add(Json.createObjectBuilder() .add("type", "home") .add("number", "212 555-1234")) .add(Json.createObjectBuilder() .add("type", "fax") .add("number", "646 555-4567"))) .build(); JsonObject can be written to JSON as follows: JsonWriter writer = ... JsonObject obj = ...; writer.write