#Gson Parsing to Object return null values

9 messages · Page 1 of 1 (latest)

alpine cliff
#

I would like to convert a json with some needed values to a java object but it returns only null values for the properties.

@Getter
@Setter
@AllArgsConstructor
public class Clerk implements Serializable {
    @SerializedName(value="cr942_name")
    private String name;
    @SerializedName(value="cr942_customernumber")
    private String customerNumber;
}
private Clerk getClerkByCustomerNumber(String customerNumber) throws IOException {
        Gson gson = new Gson();
        return gson.fromJson(getStringBodyFromResponse
                ("cr942_clerk_customers?$filter=cr942_customernumber eq " + "'" + customerNumber + "'"), Clerk.class); //-> Gives Object with null properties
    }

Is it because the json has more than just cr942_name and cr942_customername properties thus it cant convert correctly? If yes how do I filter the unneeded Json values so i can convert correctly.

shadow oakBOT
#

⌛ This post has been reserved for your question.

Hey @alpine cliff! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

alpine cliff
inner osprey
# alpine cliff

I am not sure if Gson uses SerializedName annotation. It should work if you name the fields correctly though

shadow oakBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

alpine cliff
shadow oakBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

alpine cliff
#

it was because it was nested which i didnt see with my eyes