Support for Jackson

49 views
Skip to first unread message

Shashank Tandon

unread,
Apr 23, 2015, 12:39:39 AM4/23/15
to jmapper-...@googlegroups.com
Hi,

I am using hibernate lazy fetching to avoid fetching huge amount of data. At my Jersey resource methods, I use @JsonView of "com.fasterxml.jackson" to serialize object and include only required fields.

But I think Jmapper is avoiding that and try to map whole object before serializing the object.

Is there any support for JacksonJson till now?

Alessandro Vurro

unread,
Apr 23, 2015, 5:20:06 AM4/23/15
to jmapper-...@googlegroups.com
Hi,

JacksonJson currently is not supported, but you can resolve using the MappingType Annotation in the getDestination method, or configuring only the interested fields, or using static conversion methods.
 
Share your configuration for greater support

Shashank Tandon

unread,
Apr 23, 2015, 5:51:18 AM4/23/15
to jmapper-...@googlegroups.com
My basic configuration is something like this.

@JGlobalMap(excluded = {

        "contactMethod", "contactMethodId", "readOnly", "links", "statusId", "actionResultId", "outcomeResultId",

        "contactPersons", "accountId", "contactById", "createdById", "createdBy", "contactPersonName", "creatingUserId",

        "contactByName", "contactPersonId", "opportunityId", "adCampaignId", "productId", "reminder", "taskNote",

        "documents", "promotionId", "customerName", "accountId", "invoiceId", "orderId", "status"

})

@ApiModel

@JsonIgnoreProperties(ignoreUnknown = true)

public class Task extends Base implements Serializable {


    @JsonView(Views.SummaryView.class)

    private int id;

    @JsonView(Views.SummaryView.class)

    private boolean readOnly;

    @JsonView(Views.SummaryView.class)

    private ContactMethodCodeType contactMethod;

    @JMap("dbContactType")

    @JsonView(Views.SummaryView.class)

    private Integer contactMethodId;

    @JsonView(Views.SummaryView.class)

    private Boolean contactCompleteFlag;

    @JMap("priorityType")

    @JsonView(Views.SummaryView.class)

    private TaskPriorityType priorityType;

    @JsonView(Views.SummaryView.class)

    @NotNull

    private String subject;

    @JsonView(Views.SummaryView.class)

    @NotNull

    private Date dateScheduled;

    @JsonView(Views.SummaryView.class)

    private Date createDate;


    @JMap("dbContactResultType")

    @JsonView(Views.SummaryView.class)

    private Integer statusId;

    @JsonView(Views.SummaryView.class)

    private TaskStatusCodeType status;


    @JMap("dbCustomer")

    @JsonView(Views.SummaryView.class)

    private Integer accountId;

    @JsonView(Views.SummaryView.class)

    private String customerName;


    @JMap("dbFnTransactions")

    @JsonView(Views.SummaryView.class)

    private Integer invoiceId;

    @JsonView(Views.SummaryView.class)

    private Integer orderId;


    @JMap("dbAoPromotions")

    @JsonView(Views.SummaryView.class)

    private Integer promotionId;


    @JMap("dbContactPerson")

    @JsonView(Views.SummaryView.class)

    private Integer contactPersonId;

    @JsonView(Views.SummaryView.class)

    private String contactPersonName;


    @JMap("dbUsrUsersByContactById")

    @JsonView(Views.SummaryView.class)

    @NotNull

    private Integer contactById;

    @JsonView(Views.SummaryView.class)

    private String contactByName;


    @JMap("dbTaskActionResult")

    @JsonView(Views.SummaryView.class)

    private Integer actionResultId;

    @JMap("dbTaskOutcomeResult")

    @JsonView(Views.SummaryView.class)

    private Integer outcomeResultId;

    @JMap("dbTaskEventCplinks")

    @JsonView(Views.DetailedView.class)

    private List<ContactPerson> contactPersons;


    @JMap("dbUsrUsersByCreatingUserId")

    @JsonView(Views.DetailedView.class)

    private Integer createdById;

    @JsonView(Views.DetailedView.class)

    private String createdBy;

    @JsonView(Views.DetailedView.class)

    private Integer creatingUserId;


    @JMap("dbCrmopportunity")

    @JsonView(Views.SummaryView.class)

    private Integer opportunityId;


    @JMap("dbCampaign")

    @JsonView(Views.SummaryView.class)

    private Integer adCampaignId;


    @JMap("dbAoProducts")

    @JsonView(Views.SummaryView.class)

    private Integer productId;


    @JMap("reminderDateTime")

    @JsonView(Views.SummaryView.class)

    private TaskReminderType reminder;


    @JMap("dbContactNoteses")

    @JsonView(Views.SummaryView.class)

    private ContactNotes taskNote;


    @JMap("dbContactDocLinks")

    @JsonView(Views.DetailedView.class)

    private List<ContactDocLink> documents;


and I have declared some mapping conversion methods, getters and setters in 1st class..

The other is my hibernate entity class which has object and set fields lazy fetch.


Now I try to map it using following:

I am calling the method with JSONView SummaryView, so I dont get DetailedView fields, but from my logs and debugging I find those fields are being populated and their conversion methods are being called. Since I am using this DTO class for different views so i want such kind of functionality. So that I dont need to create multiple DTO classes.

I got entity to my resource class. Lets say it is DbContact entity;

Jmapper<Task,DbContact> jmapper = new JMapper<>(Task.class,DbContact.class);

Task result = jmapper.getDestination(entity);

Since I have used JSONView here I dont 

Alessandro Vurro

unread,
Apr 23, 2015, 10:29:11 AM4/23/15
to jmapper-...@googlegroups.com
First of all only the fields configured with jmap are taken into account, so you do not need to exclude the other fields with JGlobalMap.
One solution may be to write a setup xml for every type and pass it to JMapper.

For example: 
XML mapping file: summaryView.xml 
new JMapper(...,...,"path/summaryView.xml);

XML mapping file: otherView.xml 
new JMapper(...,...,"path/otherView.xml);

However the integration with the @JsonView will be part of the roadmap.
Reply all
Reply to author
Forward
0 new messages