/** * @param s the JSON representation of the filter * @return the filter * @throws Exception */ public static Filter buildFilter(String s) throws Exception { JSONJAXBContext context = new JSONJAXBContext(JSONConfiguration.natural().build(), FilterModel.class); JSONUnmarshaller unmarshaller = context.createJSONUnmarshaller(); FilterModel model = unmarshaller.unmarshalFromJSON(new StringReader(s), FilterModel.class); return model.build(); }
private void tryIndividualsWithConfiguration(JSONConfiguration configuration) throws Exception { final JSONJAXBContext ctx = new JSONJAXBContext(configuration, AnimalList.class, Animal.class, Dog.class, Cat.class); final JSONMarshaller jm = ctx.createJSONMarshaller(); final JSONUnmarshaller ju = ctx.createJSONUnmarshaller(); Animal animalTwo; for (int i = 0; i < one.animals.size(); i++) { final StringWriter sw = new StringWriter(); Animal animalOne = one.animals.get(i); jm.marshallToJSON(animalOne, sw); System.out.println(String.format("Marshalled: %s", sw)); animalTwo = ju.unmarshalFromJSON(new StringReader(sw.toString()), Animal.class); assertEquals(animalOne, animalTwo); System.out.println( String.format( "class one = %s; class two = %s", animalOne.getClass(), animalTwo.getClass())); assertEquals(animalOne.getClass(), animalTwo.getClass()); } }