1

I'm trying to map two classes with almost the same fields: MetaInfoDTO and MetaInfo.

I've tried to configure the mapper with a default mapping. The problem is on the List<Object> values field. It has the same name on the other class. So, I guess it have to be mapped correctly. See the test at the end.

public class MetaInfoDTO
{

    private String id;
    private String key;
    private String description;
    private List<Object> values;

    //Constructors, getters and setters...
    public List<Object> getValues() {
        return values;
    }

    public void setValues(List<Object> values) {
        this.values = values;
    }
}

public class MetaInfo
{

    private String id;
    private String key;
    private String description;
    private List<Object> values;

    //Constructors, getters and setters...
    public List<Object> getValues() {
        return values;
    }

    public void setValues(List<Object> values) {
        this.values = values;
    }
}

And this orika configuration:

mapperFactory.classMap(MetaInfoDTO.class, MetaInfo.class)
        .byDefault()
        .register();

I've created a test in order to show my problem:

@Test
public void metaInfoDTOTOMetaInfoWITHVALUES()
{
    MetaInfoDTO dto = new StringMetaInfoDTO("key1", "desc1");
    MetaInfo metainfo = this.mappingResources.getMapper().map(dto, MetaInfo.class);
    for (int i = 0; i < 10; i++)
        dto.getValues().add("s" + i);

    assertThat(dto.getValues(), not(empty()));
    assertThat(metainfo.getValues(), not(empty()));   //<<<< IT'S EMPTY!!
}

Class:

public class StringMetaInfoDTO extends MetaInfoDTO
{

    public StringMetaInfoDTO(String key, String description) {
        this(key, description, new ArrayList<String>());
    }

    public StringMetaInfoDTO(String key, String description, List<String> values) {
        super(MetaInfoTypeDTO.stringType, key, description, values.stream().map(e -> (Object)e).collect(Collectors.toList()));
    }

}

So, after mapping, metainfo.getValues() is empty! Is there something wrong?


How do I fetch all mongo data which is created greater than a particular date?

I read the $gt attribute has to be used. Not able to get around this. Let's say I have some mongo data like this:

{
    "startTime" : "Sun 25 Jan 2015 07:14:26 GMT",
    "endTime" : "",
    "jobStatus" : "JOBCANCELLED",
    "uiState" : "HISTORY",
    "priority" : "SILVER"
}

That's how my start time is saved in my Mongo. If I want to get the statuses of all jobs which have the start time greater than today, How do I do it?

db.getCollection('jobsCollection').find({"startTime":{$gt: "What here?"})
4

0 回答 0