当前位置 : 主页 > 编程语言 > c++ >

ArangoDB Java 实现自定义序列化器

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt private final static ArangoDB arangoDB = new ArangoDB.Builder().registerModule(new VPackModule() { @Override public void setup(final C context) { context.registerSerializer(LocalDate.class, S_LOCAL_DATE); context.registerSeria
gistfile1.txt
private final static ArangoDB arangoDB = new ArangoDB.Builder().registerModule(new VPackModule() {
    @Override
    public 
 
  > void setup(final C context) {
        context.registerSerializer(LocalDate.class, S_LOCAL_DATE);
        context.registerSerializer(LocalDateTime.class, S_LOCAL_DATE_TIME);
        context.registerDeserializer(LocalDate.class, D_LOCAL_DATE);
        context.registerDeserializer(LocalDateTime.class, D_LOCAL_DATE_TIME);
    }

    public final VPackSerializer
  
    S_LOCAL_DATE = (builder, attribute, value, context) -> { builder.add(attribute, DateTimeFormatter.ofPattern("yyyy-MM-dd").format(value)); }; public final VPackSerializer
   
     S_LOCAL_DATE_TIME = (builder, attribute, value, context) -> { builder.add(attribute, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(value)); }; public final VPackDeserializer
    
      D_LOCAL_DATE = (parent, vpack, context) -> { return LocalDate.parse(vpack.getAsString(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); }; public final VPackDeserializer
     
       D_LOCAL_DATE_TIME = (parent, vpack, context) -> { return LocalDateTime.parse(vpack.getAsString(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); }; }).build();
     
    
   
  
 
网友评论