Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package vertigo;
- import java.time.Instant;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
- import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
- import lombok.Builder;
- import lombok.SneakyThrows;
- import lombok.Value;
- import lombok.val;
- @Value
- @Builder
- public class ValueExample {
- String name;
- int age;
- Instant now;
- }
- class Test {
- @SneakyThrows
- public static void main(String[] args) {
- val om = new ObjectMapper();
- om.registerModule(new ParameterNamesModule());
- om.registerModule(new JavaTimeModule());
- val v = ValueExample.builder()
- .name("Nick")
- .age(33)
- .now(Instant.now())
- .build();
- val jsonV = om.writeValueAsString(v);
- val v1 = om.readValue(jsonV, ValueExample.class);
- System.out.println("v = " + v);
- System.out.println("json = " + jsonV);
- System.out.println("v1 = " + v1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement