How to get the value using model if the key has space in it

16 views
Skip to first unread message

Allnvrgs1989

unread,
Feb 22, 2022, 6:48:52 AMFeb 22
to rest-a...@googlegroups.com
Hi,

I have a response that looks like this ie. there is a space in the key
{ 'first name' : test }

So i created a response model class like shown below
Class ApiResponseModel {
Private String firstName;

//getters and setters
}

But when i am parsing the response, like
response.getBody().as(ApiResponseModel.class).getFirstName, i am getting a null value. So my question is, how can i get the 'first name' value using this approach?

Thanks for your help.

Regards,
Allen


Sent from my iPhone

Johan Haleby

unread,
Feb 22, 2022, 8:27:09 AMFeb 22
to rest-a...@googlegroups.com
Hi, 

While you may get an answer here, I would suggest asking this question in some Jackson-related forum (I assume you're using jackson). I'm pretty sure there's an annotation that lets you specify the field name, but I don't remember it off the top of my head.

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rest-assured/25CCA82B-58BE-42B2-B108-CF4EFC70C357%40gmail.com.

Nava Kishore Dasari

unread,
Feb 23, 2022, 4:00:36 AMFeb 23
to rest-a...@googlegroups.com
Hi,
You can use jackson.annotation.JsonProperty
example:

public class User{

@JsonProperty("first name")
Private String firstName;
}

Reply all
Reply to author
Forward
0 new messages