java - How can I call the class's default Jackson serializer from inside custom serializer for that class? -


i need write custom jackson json serializer class following:

  • if object iscustomjson(), should encoded string "custom" (obviously, assuming object's class has boolean iscustomjson() method)
  • if object isn't iscustomjson(), should encoded using default jackson json serializer class have been used if didn't have registered custom serializer.

i'm guessing code this:

public class itemserializer extends stdserializer<item> { // add boilerplate     @override     public void serialize (         item value, jsongenerator jgen, serializerprovider provider) { // add throws         if (value.iscustomjson()) {             jgen.writestring("custom");         } else {             jgen.needtowritestandardencodedjsonserialization(value);             // profit???          }     } } 

how implement jgen.needtowritestandardencodedjsonserialization(value); piece?


side note: in case i'm wrestling x-y problem, reason behind doing weird logic need add support old api in code, expects different json encoding default 1 class structure provides, due class restructuring in server (old code can't changed include new class structure). approach to: 1. detect old api request; 2. flag old api in data via iscustomjson() , 3. write custom jackson json serializer outputs json old api can understand; while letting requests new api use default normal json serializer default class. if x-y problem; please center answers around "how technically achieve asked" since want know answer not solve problem improve knowledge of jackson


Comments

Popular posts from this blog

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

node.js - Node js - Trying to send POST request, but it is not loading javascript content -