0

I have a nested json response from my api like this:

{
    "notif_title":"Generic Notification",
    "notif_message":"you have a message",
    "url":"https://www.google.com",
    "set_profile":{
                   "54fdc8eb77761b8844e65f96":"1"
                  }
}

Problem

The problem is that I want to get the set_profile json as a string no as an object because that object will be changing and I don't need to make any changes to it.

Question

Can I get that object as a string using retrofit?, thanks

2
  • And what exactly would you want to be the value of that string? The whole JSON object, including curly braces and all? Either way, you should be able to do that using a custom TypeAdapterFactory. Commented Jul 7, 2015 at 18:10
  • yes, including all. Will look at the TypeAdapterFactory option, thanks Commented Jul 7, 2015 at 18:42

1 Answer 1

1

In retrofit if you want to parse JSON with dynamic keys (with dynamic names) you need to use HashMap for sure.

public class Name {
    @SerializedName("notif_title")
    @Expose
    private String notif_title;

    @SerializedName("notif_message")
    @Expose
    private String notif_message;

    @SerializedName("url")
    @Expose
    private String url;

    @SerializedName("set_profile")
    @Expose
    private Map<String, String> set_profile;
    //...setters and getters
}

hope this help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.