Issue
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?
Solution
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;
}
Answered By - Thirumal
Answer Checked By - Senaida (JavaFixing Volunteer)