Question

I'm using Apache Wink client with MOXy to make RESTful web service calls to Microsoft Sharepoint.

I'm close to completing my JSON/POJO mapping, but I'm stuck on 3 remaining elements: CreatedBy, ModifiedBy, and Attachments. All 3 objects have values of null when I inspect the Results objects in a debugger.

Here's the JSON response I'm trying to map:

{
"d": {
    "results": [
        {
            "__metadata": {
                "uri": "https://worksites.connect.somecompany.com/sites/UniversityRelations/_vti_bin/listdata.svc/UserInformationList(1)", 
                "etag": "W/\"63\"", 
                "type": "Microsoft.SharePoint.DataService.UserInformationListItem"
            }, 
            "ContentTypeID": "0x010A005977DE477030BD4EADA71E1A1B9F4069", 
            "Name": "Some name", 
            "Account": "Some account", 
            "WorkEMail": null, 
            "MobilePhone": null, 
            "AboutMe": null, 
            "SIPAddress": null, 
            "IsSiteAdmin": true, 
            "Deleted": false, 
            "Picture": null, 
            "Department": null, 
            "Title": null, 
            "FirstName": "Some first name", 
            "LastName": "Some last name", 
            "WorkPhone": null, 
            "UserName": "Some username", 
            "WebSite": null, 
            "AskMeAbout": null, 
            "Office": null, 
            "Id": 1, 
            "ContentType": "Person", 
            "Modified": "\/Date(1384765618000)\/", 
            "Created": "\/Date(1372051813000)\/", 
            "CreatedBy": {
                "__deferred": {
                    "uri": "https://worksites.connect.somecompany.com/sites/UniversityRelations/_vti_bin/listdata.svc/UserInformationList(1)/CreatedBy"
                }
            }, 
            "CreatedById": 1, 
            "ModifiedBy": {
                "__deferred": {
                    "uri": "https://worksites.connect.somecompany.com/sites/UniversityRelations/_vti_bin/listdata.svc/UserInformationList(1)/ModifiedBy"
                }
            }, 
            "ModifiedById": 1073741823, 
            "Owshiddenversion": 63, 
            "Version": "1.0", 
            "Attachments": {
                "__deferred": {
                    "uri": "https://worksites.connect.somecompany.com/sites/UniversityRelations/_vti_bin/listdata.svc/UserInformationList(1)/Attachments"
                }
            }, 
            "Path": "/sites/UniversityRelations/_catalogs/users"
        }]
    }
}

Here's my Results class:

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Chris Harris
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)  <!-- Allows the __Metadata class to be mapped -->
public class Results {
    private __Metadata __metadata;
    @XmlAttribute(name="ContentTypeID")
    private String contentTypeID;
    @XmlAttribute(name="Name")
    private String name;
    @XmlAttribute(name="Account")
    private String account;
    @XmlAttribute(name="WorkEMail")
    private String workEMail;
    @XmlAttribute(name="MobilePhone")
    private String mobilePhone;
    @XmlAttribute(name="AboutMe")
    private String aboutMe;
    @XmlAttribute(name="SIPAddress")
    private String sIPAddress;
    @XmlAttribute(name="IsSiteAdmin")
    private String isSiteAdmin;
    @XmlAttribute(name="Deleted")
    private String deleted;
    @XmlAttribute(name="Picture")
    private String picture;
    @XmlAttribute(name="Department")
    private String department;
    @XmlAttribute(name="Title")
    private String title;
    @XmlAttribute(name="FirstName")
    private String firstName;
    @XmlAttribute(name="LastName")
    private String lastName;
    @XmlAttribute(name="WorkPhone")
    private String workPhone;
    @XmlAttribute(name="UserName")
    private String userName;
    @XmlAttribute(name="WebSite")
    private String webSite;
    @XmlAttribute(name="AskMeAbout")
    private String askMeAbout;
    @XmlAttribute(name="Office")
    private String office;
    @XmlAttribute(name="Id")
    private String id;
    @XmlAttribute(name="ContentType")
    private String contentType;
    @XmlAttribute(name="Modified")
    private String modified;
    @XmlAttribute(name="Created")
    private String created;
    @XmlAttribute(name="CreatedBy")
    private CreatedBy createdBy;
    @XmlAttribute(name="CreatedById")
    private String createdById;
    @XmlAttribute(name="ModifiedBy")
    private ModifiedBy modifiedBy;
    @XmlAttribute(name="ModifiedById")
    private String modifiedById;
    @XmlAttribute(name="Owshiddenversion")
    private String owshiddenversion;
    @XmlAttribute(name="Version")
    private String version;
    @XmlAttribute(name="Attachments")
    private Attachments attachments;
    @XmlAttribute(name="Path")
    private String path;
}

Since the CreatedBy, ModifiedBy, and Attachments classes are currently configured the same way, here's just my CreatedBy class:

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Chris Harris
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class CreatedBy {
    private __Deferred __deferred;

    public __Deferred getDeferred() {
        return __deferred;
    }

    public void setDeferred(__Deferred __deferred) {
        this.__deferred = __deferred;
    }
}

How can I map CreatedBy, ModifiedBy, and Attachments?

Was it helpful?

Solution

Currently you have everything on the Results class mapped with @XmlAttribute. @XmlAttribute should only be used for simple properties (i.e. String, int, byte[]) or domain objects with one field/property mapped with @XmlValue. You should change your mapping to be:

@XmlElement(name="ModifiedBy")
private ModifiedBy modifiedBy;

Also unless you are also marshalling this object model to XML I would change all your @XmlAttribute mappings to @XmlElement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top