0

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?

1 Answer 1

0

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;
}
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.