Search code examples
javarestobject-type

Restful system call class field members different then backend class field types


I'm working on a Restful Java system that processes entities with time-related fields. The types of these fields are long, in milliseconds. However, the time fields of the Restful calls are of type Instant. What is the best way to make this conversion?

What i'm thinking now is to define "twin" types for entities-with-time-fields, the type of those fields being Instant in these twins. The system will accept calls of those twin types, then will convert them to the system's own types before dispatching the calls to the backend.

But I feel there are more elegant ways.

What's the best way to do this?


Solution

  • use MapStruct mapper. It's easy to configure

    see Mapstruct LocalDateTime to Instant