YearSerTest.java
/*
* Copyright 2013 FasterXML.com
*
* Licensed 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 com.fasterxml.jackson.datatype.jsr310.ser;
import java.time.Year;
import java.time.temporal.Temporal;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.MockObjectConfiguration;
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase;
import static org.junit.jupiter.api.Assertions.*;
public class YearSerTest extends ModuleTestBase
{
private final ObjectMapper MAPPER = newMapper();
@Test
public void testDefaultSerialization() throws Exception
{
assertEquals("1986",
MAPPER.writeValueAsString(Year.of(1986)));
assertEquals("2013",
MAPPER.writeValueAsString(Year.of(2013)));
}
@Test
public void testSerializationWithTypeInfo() throws Exception
{
ObjectMapper mapper = newMapper()
.addMixIn(Temporal.class, MockObjectConfiguration.class);
String value = mapper.writeValueAsString(Year.of(2005));
assertEquals("[\"" + Year.class.getName() + "\",2005]", value);
}
}