2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.test.issues;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.fasterxml.jackson.databind.SerializationFeature;
27 import java.io.IOException;
28 import org.junit.Test;
29 import org.mockito.Mockito;
30 import org.opendaylight.yangtools.yang.common.Uint32;
32 public class TestIssue227 extends Mockito {
34 static String inputJsonString = "{\"value1\":\"forty-two\", \"value2\":\"forty-three\"}";
35 static String inputJsonNumber = "{\"value1\":42, \"value2\":43}";
38 public void testWithException() {
39 String inputJson = inputJsonNumber;
40 System.out.println("Input " + inputJson);
42 ObjectMapper mapper = new ObjectMapper();
43 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
45 doMapping(mapper, inputJson);
49 public void testWithMixin() {
50 String inputJson = inputJsonNumber;
51 System.out.println("Input " + inputJson);
53 ObjectMapper mapper = new ObjectMapper();
54 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
55 mapper.addMixIn(TestBuilder.class, IgnoreFooSetValueIntMixIn.class);
57 doMapping(mapper, inputJson);
61 private void doMapping(ObjectMapper mapper, String json) {
64 foo = mapper.readValue(json.getBytes(), TestBuilder.class);
65 System.out.println("Foo " + foo);
66 System.out.println(mapper.writeValueAsString(foo));
67 } catch (IOException e) {
72 static class TestBuilder {
74 private String value1;
75 private String value2;
81 public void setValue1(String value) {
85 public void setValue1(int value) {
86 this.value1 = String.valueOf(value);
89 public void setValue1(long value) {
90 this.value1 = String.valueOf(value);
93 public void setValue1(Uint32 value) {
94 this.value1 = String.valueOf(value);
97 public String getValue2() {
101 public void setValue2(String value) {
105 public void setValue2(int value) {
106 this.value2 = String.valueOf(value);
110 public String toString() {
111 return "Foo [value1=" + value1 + ", value2=" + value2 + "]";
117 private abstract class IgnoreFooSetValueIntMixIn {
119 public abstract void setValue1(String value);
122 public abstract void setValue2(String value);