airavata-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marcus Christie (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (AIRAVATA-2751) Dozer custom mapping to skip primitive fields that aren't set
Date Thu, 12 Apr 2018 20:35:00 GMT

     [ https://issues.apache.org/jira/browse/AIRAVATA-2751?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Marcus Christie resolved AIRAVATA-2751.
---------------------------------------
    Resolution: Fixed

> Dozer custom mapping to skip primitive fields that aren't set
> -------------------------------------------------------------
>
>                 Key: AIRAVATA-2751
>                 URL: https://issues.apache.org/jira/browse/AIRAVATA-2751
>             Project: Airavata
>          Issue Type: Bug
>            Reporter: Marcus Christie
>            Assignee: Marcus Christie
>            Priority: Major
>
> I'm finding that primitive fields that aren't set on a thrift model, like {{long}}, are
mapped into entities as a 0.  The Dozer mapping (see ObjectMapperSingleton) isn't calling
{{isSet}} on the thrift models to make sure that they are mapped.
> Here's some pseudo code that I think would do the trick, although I'm not sure if a CustomFieldMapper
is the right way to customize this in Dozer (seemed like the best option given the research
I did):
> {code}
>     public static ObjectMapperSingleton getInstance(){
>         if(instance == null) {
>             instance = new ObjectMapperSingleton();
>             instance.setCustomFieldMapper(new CustomFieldMapper() {
>                 @Override
>                 public boolean mapField(Object source, Object destination, Object sourceFieldValue,
ClassMap classMap, FieldMap fieldMap) {
>                     if (source instanceof TBase) {
>                         TBase thriftSource = (TBase) source;
>                         // TODO: following doesn't work, needs reflection
>                         srcField = thriftSource.getClass()._Fields.byName(fieldMap.getSrcFieldName());
>                         if (!thriftSource.isSet(srcField)) {
>                             // Just skipping mapping field if not set on Thrift source
model
>                             return true;
>                         }
>                     }
>                     return false;
>                 }
>             });
>         }
>         return instance;
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message