Thirumal
Thirumal

Reputation: 9646

How to map gremlin query output Map<Object, Object> to java Pojo class?

How to map gremlin query output Map<Object, Object> to java Pojo class?

Gremlin returns vertex properties in Object, how to convert/map it to POJO Class?

Do we need to write a separate mapper class?

Upvotes: 0

Views: 288

Answers (1)

Thirumal
Thirumal

Reputation: 9646

Able to convert, using fasterxml object mapper

public static <T> T convert(Map<Object, Object> map, Class<T> t) {
    final ObjectMapper objectMapper = JsonMapper.builder() // or different mapper for other format
            .addModule(new ParameterNamesModule())
            .addModule(new Jdk8Module())
            .addModule(new JavaTimeModule())
            .build();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    try {
       return objectMapper.convertValue(map, objectMapper.getTypeFactory().constructType(t));
    } catch (Exception e) {
       System.err.println(e)    
    }
    return null;
}
    

Upvotes: 0

Related Questions