|
| 1 | +/* |
| 2 | + * Copyright 2013 FasterXML.com |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | + * not use this file except in compliance with the License. You may obtain |
| 6 | + * a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the license for the specific language governing permissions and |
| 14 | + * limitations under the license. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.fasterxml.jackson.datatype.jsr310.failing; |
| 18 | + |
| 19 | +import java.time.Year; |
| 20 | +import java.time.temporal.Temporal; |
| 21 | + |
| 22 | +import com.fasterxml.jackson.annotation.JsonFormat; |
| 23 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 24 | +import com.fasterxml.jackson.datatype.jsr310.MockObjectConfiguration; |
| 25 | +import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase; |
| 26 | + |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +import static org.junit.Assert.assertEquals; |
| 30 | +import static org.junit.Assert.assertTrue; |
| 31 | + |
| 32 | +public class YearDeser78Test extends ModuleTestBase |
| 33 | +{ |
| 34 | + // [module-java8#78] |
| 35 | + final static class ObjectTest { |
| 36 | + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "'Y'yyyy") |
| 37 | + public Year value; |
| 38 | + |
| 39 | + public ObjectTest(Year y) { |
| 40 | + value = y; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + private final ObjectMapper MAPPER = newMapper(); |
| 45 | + |
| 46 | + // [module-java8#78] |
| 47 | + @Test |
| 48 | + public void testWithCustomFormat() throws Exception |
| 49 | + { |
| 50 | + ObjectTest input = new ObjectTest(Year.of(2018)); |
| 51 | + String json = MAPPER.writeValueAsString(input); |
| 52 | + assertEquals("{\"customYear\":\"Y2018\"}", json); |
| 53 | + ObjectTest result = MAPPER.readValue(json, ObjectTest.class); |
| 54 | + assertEquals(input, result); |
| 55 | + } |
| 56 | +} |
0 commit comments