public void testListBean() throws Exception { final int COUNT = 13; ArrayList<CtorValueBean> beans = new ArrayList<CtorValueBean>(); for (int i = 0; i < COUNT; ++i) { beans.add(new CtorValueBean(i)); } BeanWithList bean = new BeanWithList(beans); StringWriter sw = new StringWriter(); MAPPER.writeValue(sw, bean); BeanWithList result = MAPPER.readValue(sw.toString(), BeanWithList.class); assertEquals(bean, result); }
public void testSimpleBean() throws Exception { ArrayList<Object> misc = new ArrayList<Object>(); misc.add("xyz"); misc.add(42); misc.add(null); misc.add(Boolean.TRUE); TestBean bean = new TestBean(13, -900L, "\"test\"", new URL("http://foobar.com"), misc); // Hmmh. We probably should use serializer too... easier String json = MAPPER.writeValueAsString(bean); TestBean result = MAPPER.readValue(json, TestBean.class); assertEquals(bean, result); }
/** * Method that will construct a parser (possibly a sequence) that contains all given sub-parsers. * All parsers given are checked to see if they are sequences: and if so, they will be * "flattened", that is, contained parsers are directly added in a new sequence instead of adding * sequences within sequences. This is done to minimize delegation depth, ideally only having just * a single level of delegation. */ public static JsonParserSequence createFlattened( boolean checkForExistingToken, JsonParser first, JsonParser second) { if (!(first instanceof JsonParserSequence || second instanceof JsonParserSequence)) { return new JsonParserSequence(checkForExistingToken, new JsonParser[] {first, second}); } ArrayList<JsonParser> p = new ArrayList<JsonParser>(); if (first instanceof JsonParserSequence) { ((JsonParserSequence) first).addFlattenedActiveParsers(p); } else { p.add(first); } if (second instanceof JsonParserSequence) { ((JsonParserSequence) second).addFlattenedActiveParsers(p); } else { p.add(second); } return new JsonParserSequence(checkForExistingToken, p.toArray(new JsonParser[p.size()])); }