Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * 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;
Serializer for Java 8 temporal java.time.Years.

Author(s):
Nick Williams
Since:
2.2.0
    private static final long serialVersionUID = 1L;
    public static final YearSerializer INSTANCE = new YearSerializer();
    private YearSerializer() {
        this(nullnull);
    }
    private YearSerializer(Boolean useTimestampDateTimeFormatter dtf) {
        super(Year.classuseTimestampdtf);
    }
    @Override
    protected YearSerializer withFormat(Boolean useTimestampDateTimeFormatter dtf) {
        return new YearSerializer(useTimestampdtf);
    }
    @Override
    public void serialize(Year yearJsonGenerator generatorSerializerProvider providerthrows IOException
    {
        if (useTimestamp(provider)) {
            generator.writeNumber(year.getValue());
        } else {
            String str = ( == null) ? year.toString() : year.format();
            generator.writeString(str);
        }
    }
    @Override
    protected void _acceptTimestampVisitor(JsonFormatVisitorWrapper visitorJavaType typeHintthrows JsonMappingException
    {
        JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint);
        if (v2 != null) {
            v2.numberType(..);
        }
    }
New to GrepCode? Check out our FAQ X