2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.util;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
29 import com.fasterxml.jackson.core.JsonParseException;
30 import com.fasterxml.jackson.databind.JsonMappingException;
32 import java.io.IOException;
34 import org.junit.Test;
36 public class JacksonUtilsTest {
38 public static class TestClass extends TestObject {
43 public TestClass(String value1, String value2) {
51 public String getTest2() {
55 public void setTest2(String test2) {
59 public TestObject2 getObject2() {
63 public void setObject2(TestObject2 object2) {
64 this.object2 = object2;
69 public void testGetObjectMapperInstance() {
70 assertNotNull(JacksonUtils.getObjectMapperInstance());
74 * This method test that the security hole in Jackson is not enabled in the
75 * default ObjectMapper.
77 * @throws JsonParseException
79 * @throws JsonMappingException
85 public void testCreateBeanDeserializer() throws JsonParseException, JsonMappingException, IOException {
86 TestClass test = new TestClass("value1", "value2");
87 test.setObject2(new TestObject2("test3"));
88 Object testObject = JacksonUtils.getObjectMapperInstance().readValue(
89 "[\"org.onap.clamp.clds.util.JacksonUtilsTest$TestClass\",{\"test\":\"value1\",\"test2\":\"value2\",\"object2\":[\"org.onap.clamp.clds.util.TestObject2\",{\"test3\":\"test3\"}]}]",
91 assertNotNull(testObject);
92 assertFalse(testObject instanceof TestObject);
93 assertFalse(testObject instanceof TestClass);