// [JACKSON-605] public void testClassWithParams() throws IOException { String json = MAPPER.writeValueAsString(new ParamClassBean("Foobar")); ParamClassBean result = MAPPER.readValue(json, ParamClassBean.class); assertEquals("Foobar", result.name); assertSame(String.class, result.clazz); }
public void testRegexps() throws IOException { final String PATTERN_STR = "abc:\\s?(\\d+)"; Pattern exp = Pattern.compile(PATTERN_STR); /* Ok: easiest way is to just serialize first; problem * is the backslash */ String json = MAPPER.writeValueAsString(exp); Pattern result = MAPPER.readValue(json, Pattern.class); assertEquals(exp.pattern(), result.pattern()); }
// [Issue#239] public void testByteBuffer() throws Exception { byte[] INPUT = new byte[] {1, 3, 9, -1, 6}; String exp = MAPPER.writeValueAsString(INPUT); ByteBuffer result = MAPPER.readValue(exp, ByteBuffer.class); assertNotNull(result); assertEquals(INPUT.length, result.remaining()); for (int i = 0; i < INPUT.length; ++i) { assertEquals(INPUT[i], result.get()); } assertEquals(0, result.remaining()); }
/** Related to issues [JACKSON-155], [#170]. */ public void testFile() throws Exception { // Not portable etc... has to do: File src = new File("/test").getAbsoluteFile(); String abs = src.getAbsolutePath(); // escape backslashes (for portability with windows) String json = MAPPER.writeValueAsString(abs); File result = MAPPER.readValue(json, File.class); assertEquals(abs, result.getAbsolutePath()); // Then #170 final ObjectMapper mapper2 = new ObjectMapper(); mapper2.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE); result = mapper2.readValue(json, File.class); assertEquals(abs, result.getAbsolutePath()); }
// [JACKSON-888] public void testStackTraceElement() throws Exception { StackTraceElement elem = null; try { throw new IllegalStateException(); } catch (Exception e) { elem = e.getStackTrace()[0]; } String json = MAPPER.writeValueAsString(elem); StackTraceElement back = MAPPER.readValue(json, StackTraceElement.class); assertEquals("testStackTraceElement", back.getMethodName()); assertEquals(elem.getLineNumber(), back.getLineNumber()); assertEquals(elem.getClassName(), back.getClassName()); assertEquals(elem.isNativeMethod(), back.isNativeMethod()); assertTrue(back.getClassName().endsWith("TestJdkTypes")); assertFalse(back.isNativeMethod()); }