Advertisement
NLinker

Lombok example

Feb 24th, 2017
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package vertigo;
  2.  
  3. import java.time.Instant;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
  6. import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
  7. import lombok.Builder;
  8. import lombok.SneakyThrows;
  9. import lombok.Value;
  10. import lombok.val;
  11.  
  12. @Value
  13. @Builder
  14. public class ValueExample {
  15.     String name;
  16.     int age;
  17.     Instant now;
  18. }
  19.  
  20. class Test {
  21.  
  22.     @SneakyThrows
  23.     public static void main(String[] args) {
  24.         val om = new ObjectMapper();
  25.         om.registerModule(new ParameterNamesModule());
  26.         om.registerModule(new JavaTimeModule());
  27.         val v = ValueExample.builder()
  28.             .name("Nick")
  29.             .age(33)
  30.             .now(Instant.now())
  31.             .build();
  32.         val jsonV = om.writeValueAsString(v);
  33.         val v1 = om.readValue(jsonV, ValueExample.class);
  34.         System.out.println("v = " + v);
  35.         System.out.println("json = " + jsonV);
  36.         System.out.println("v1 = " + v1);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement