Пример #1
0
 @Override
 public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException {
   if (jgen instanceof TokenBuffer) {
     jgen.setCodec(
         null); // So next writeObject will embed Date directly, not invoke codec again
   }
   super.serialize(value, jgen, provider);
 }
Пример #2
0
 public void setSource(TreeNode tree) throws IOException {
   JsonFactory jsonFactory = new JsonFactory();
   if (buffer == null) {
     buffer = Unpooled.buffer();
   } else {
     buffer.clear();
   }
   type = QueueMessageType.JSON;
   try (ByteBufOutputStream outputStream = new ByteBufOutputStream(buffer)) {
     JsonGenerator generator = jsonFactory.createGenerator(outputStream);
     generator.setCodec(new ObjectMapper());
     generator.writeTree(tree);
     generator.close();
   }
 }