Question: I have a Json string which has a string message field.
String:

```
{  "Type" : "Text",
   "Subject" : "data received",
   "Message" :"{\\"language\\":\\"US\\",\\"data\\":\\"signature\\"}"
}

```

I want to convert it into the following structure:
Notification.java

```
public class Notification {
  String type;
  String subject;
  Message message;
}

```

Message.java

```
public class Message {
  String language;
  String data;
}

```

Is there a way in which I can directly convert the string to a Java object of the above structure? I want to avoid deserializing twice.

Answer: 
I am not sure my solution is acceptable since it does require additional explicit call to `ObjectMapper` to perform deserialization of the string value of `Message`.  

However, this is it is done during the buildup of `Notification` object and does not require a String message property.

You need to add a ctor with String argument to `Message` class, where you can deserialize the String into Map and extract the instance propertieds:

```
public Message(String str) {
    try {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = 
                (Map<String, Object>)new ObjectMapper().readValue(str, Map.class);
        language = map.containsKey("language") ? map.get("language").toString() : null ;
        data = map.containsKey("data") ? map.get("data").toString() : null ;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

```

the new ctor will be called by Jackson when you deserialize a Notification object: 

```
Notification n = (Notification)new ObjectMapper().readValue(reader, Notification.class);

```
You can convert json string into key-value pairs in Map.You will have to do twice as the `Message` value is again a json string.Use `org.json` for JSONObject

```
    Map<String, String> map = new HashMap<String, String>();
    JSONObject j = new JSONObject(str);
    Iterator<String> keys = j.keys();

    while( keys.hasNext() ){
        String key = (String)keys.next();
        String val = j.getString(key); 
        map.put(key, val);}

```

Then retrieve the values by iterating over the keys and pass the values into the class constructor

Then `map.get(key)` can be used to retrieve the values and will be passed into constructors of the classes.