File: TestMaterializingDeserializer.java

package info (click to toggle)
libjackson-json-java 1.9.13-2~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,420 kB
  • sloc: java: 88,999; xml: 1,382; sh: 37; makefile: 26
file content (61 lines) | stat: -rw-r--r-- 2,170 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.example;

import java.io.StringWriter;

import junit.framework.TestCase;

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.deser.MaterializingDeserializerFactory;
import org.codehaus.jackson.map.deser.StdDeserializerProvider;

import com.g414.jackson.proxy.ProxySerializerFactory;

/**
 * Exercise the deserializer...
 */
public class TestMaterializingDeserializer extends TestCase {
	public void testExample() throws Exception {
		ExampleImpl impl = new ExampleImpl();

		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializerFactory(new ProxySerializerFactory());

		MaterializingDeserializerFactory df = new MaterializingDeserializerFactory();
		StdDeserializerProvider dp = new StdDeserializerProvider(df);
		mapper.setDeserializerProvider(dp);

		// Testing Example1
		StringWriter w1 = new StringWriter();
		mapper.writeValue(w1, impl.asExample1());
		String w1Value = w1.toString();
		Example1 w1in = mapper.readValue(w1Value, Example1.class);

		assertEquals("4660", w1in.getA().toString());
		assertEquals("Foo", w1in.getB().toString());

		// Testing Example2 ...
		StringWriter w2 = new StringWriter();
		mapper.writeValue(w2, impl.asExample2());
		String w2Value = w2.toString();

		Example2 w2in = mapper.readValue(w2Value, Example2.class);
		assertEquals("305419896", w2in.getC().toString());
	}
}