tags:

views:

23

answers:

0

Sorry if the title is not clear... couldn't find better

org.json.JSONWriter has the strange limitation of 20 as a maximum nesting depth which is causing me troubles. I am stuck to the library as I have to implement a third-party interface having a method:

void write(JSONWriter writer);

the only workaround I can think of is to use a different JSON library in my implementation class. However; how do I have the new library writing to the passed wrtier (which is of type org.json.JSONWriter)? I managed to have that working using reflection. but feel that this is not the best solution and afraid that this might not be always working due to security/configuration-related issues (completely not sure if this is really a concern). any suggestion? the code I am using for reflection is below it uses Jackson lib. My application is a web application.

JsonFactory factory = new JsonFactory();
Writer w;
Field protectedWriterField;
protectedWriterField = JSONWriter.class.getDeclaredField("writer");
protectedWriterField.setAccessible(true);
w = (Writer) protectedWriterField.get(writer);
JsonGenerator jwriter =  factory.createJsonGenerator(w);
//writing