• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unrecognized Property in fetching data from JSONObject in Jersey web service

 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I need to convert a certain JSON string to a Java object. I am using Jackson for JSON handling.
Here is my Java class-

Here is the web service code-

This throws exception UnrecognizedPropertyException with message "Unrecognized field "email_id" (Class jaxrs.RequestClass), not marked as ignorable".

In case i am not using the annotation @JsonIgnoreProperties(ignoreUnknown = true) in my Java class, the output I am getting on line 09 is -

null myPassword

So I don't want to ignore Unrecognized field instead I want to get the value of email_id.

Please tell why It shows email_id as Unrecognized field while password is fetched successfully.

Thanks in advance
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try changing email_id to emailId in RequestClass also what are the annotations on your RequestClass apart from @XmlRootElement?

-P
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praful Thakare wrote:try changing email_id to emailId in RequestClass also what are the annotations on your RequestClass apart from @XmlRootElement?

-P

Thanks for the reply Praful.
Even changing email_id to emailId is not working. I am using annotations @XmlRootElement and @JsonIgnoreProperties(ignoreUnknown = true) on class level.
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this



and request in RestClient (firefox)

 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Praful,
I tried this solution but it din't help. I am still getting same output.
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm..something else is wrong with your environment, as I tired it and is working fine, I am using Jersy-server1.16 and tomcat in eclipse + firefox to send request.
how does your client request look like?
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the same tools as you mentioned.
I am sending request from Android. Here is code on client side-


I am sure for the client that its working fine as I tested the data in the JSON string I am receiving at the serve end is correct.
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to change email_id to emailId in client as well data.put("email_id", strEmailId);... and hope strEmailId has some not null value...

also make some changes to SOP in server to make sure the changes are deployed correctly.
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Changing "email_id" to "emailId" worked!!
But i am not getting how it was getting effected by this. I think its just a String and i can name it whatever i want. I know that String name on both server side and client side must be same but what was the problem when i was putting "email_id" on both side?
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java camelCase naming convention is used just because the code look consistent, it doesn't look ugly. I didn't even see it as a requirement? Please tell me what is the reason that it is mandatory to write variable names in camelCase here.
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


what was the problem when i was putting "email_id" on both side?


there is no problem with email_id the issue is the getter and setter not following javabean standard, so getEmailId or setEmailId is not valid for email_id. hence it should be emailId

or if you want it for some reason to be email_id then use following annotation that will use fields and not getter/setters.

@XmlAccessorType(XmlAccessType.FIELD)

-P
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got is. Thanks a lot for the help Praful. Cheers
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!