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] [Created] (AIRAVATA-2751) Dozer custom mapping to skip primitive fields that aren't set
Date Wed, 11 Apr 2018 20:39:00 GMT
Marcus Christie created AIRAVATA-2751:
-----------------------------------------

             Summary: 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


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