How to map Works JSON Object

155 views
Skip to first unread message

Will J

unread,
Jul 8, 2021, 1:56:16 PM7/8/21
to ORCID API Users
Hello, 

I'm having a hard time mapping the works Schema to JSON values using Java RestClient.  

Is there a place where I can find POJOs that maps ORCID info to JSON via JAVA and rest client?  Or are there any recent JAVA ORCID repos anywhere?

These are the steps that I have done so far.

1. Created a sandbox account for public api.  
2. Added information to my orcid record: Employment, Education, Works, etc..

3. Grabbed the pub sandbox url and plugged it into my properties/yml file.  
orcidPublicApiUrlWorks = https://pub.sandbox.orcid.org/v3.0/<ORCID>/works

4. Tested GET commands in Swagger.

I would like to just test first before OAuth integration.

I tested with the easiest GET first https://pub.sandbox.orcid.org/v3.0/<ORCID>/email
one first and I get back JSON data.    

I would assume it would be straight forward getting items if I map it correctly in my pojos using rest template like this.

WorksInput worksResults = restTemplate.getForObject(orcidPublicApiUrlWorks, WorksInput.class); 

I have approximately 30 pojos that will be used for works...see below

        WorksInput pojo below: 
@JsonProperty("last-modified-date")
private LastModifiedDate lastModifiedDate; 
private List<Group> group; 
private String path;
       LastModifiedDate Pojo Below:
       public class LastModifiedDate {
private String value; 
public String getValue(){
  return value; 
  }
public void setValue(String input){
  this.value = input;
  }
  
       Group Pojo below:   
       public class Group {
       @JsonProperty("last-modified-date")
       private LastModifiedDate lastModifiedDate;
       @JsonProperty("external-ids")
       private ExternalIds externalIds;
       @JsonProperty("work-summary")
       private List<WorkSummary> workSummary = new ArrayList<WorkSummary>();
       @JsonIgnore
       private Map<String, Object> additionalProperties = new HashMap<String, Object>();
etc..etc...etc
The first error message I received was this...() Then I started adding a constructor to group with a json annotation.  Didn't work.
MismatchedInputException: Cannot construct instance of `org.nrt.orcid.pojo.Group` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('2021-07-05T13:29:05.801Z')
So I went back to last modified date and got this error so I added this @JsonProperty("last-modified-date") because java doesn't accept (-) dashes in strings 
and I have to match the exact name of the data element coming back.
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `org.nrt.orcid.pojo.LastModifiedDate` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('2021-07-05T13:29:05.801Z')
This error caught my eye.  
RestClientException: Error while extracting response for type [class org.nrt.orcid.pojo.WorksInput] and content type [application/xml;charset=UTF-8];
I made some changes and now im here after adding HttpMessageConverter code.
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

Thank you for any assistance you may provide.

Nathan Tenney

unread,
Jul 8, 2021, 4:54:20 PM7/8/21
to ORCID API Users
Will,

Here is a sample that I put together that converts the schema to POJO's. I'm making use of the gson library to do this.


--
You received this message because you are subscribed to the Google Groups "ORCID API Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orcid-api-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orcid-api-users/811324c0-e94c-4727-bc19-57c2bfaf260bn%40googlegroups.com.


--
Nathan Tenney
USU Alumni

Demeranville, Tom

unread,
Jul 9, 2021, 5:47:29 AM7/9/21
to Will J, ORCID API Users
Hi therel,

You might want to check out our Java model in Maven: https://mvnrepository.com/artifact/org.orcid/orcid-model 

This is the same model we use to serialize API responses in JSON, so it works really well.

Tom Demeranville
Product Director
ORCID Inc


--
Message has been deleted

Will J

unread,
Jul 9, 2021, 11:06:44 PM7/9/21
to ORCID API Users
Nathan,  thanks a bunch.  Your videos show a nice real life example and will definitely assist me once I get to OAuth integration.

Tom, I'm able to get data back from my Orcid.  I wasn't setting my `Content-Type` and `Accept` headers properly.  Now I will use the  Orcid  model for mapping.  Thanks again.  :)

Reply all
Reply to author
Forward
0 new messages