Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.ser.std;
  
  import java.io.*;
  import java.util.*;
  
  
Class that providers access to serializers user for non-structured JDK types that are serializer as scalars; some using basic ToStringSerializer, others explicit serializers.
 
 public class StdJdkSerializers
 {
    
Method called by com.fasterxml.jackson.databind.ser.BasicSerializerFactory to access all serializers this class provides.
 
     public static Collection<Map.Entry<Class<?>, Object>> all()
     {
         HashMap<Class<?>,Objectsers = new HashMap<Class<?>,Object>();
 
         // First things that 'toString()' can handle
         final ToStringSerializer sls = .;
 
         sers.put(java.net.URL.classsls);
         sers.put(java.net.URI.classsls);
 
         sers.put(Currency.classsls);
         sers.put(UUID.classnew UUIDSerializer());
         sers.put(java.util.regex.Pattern.classsls);
         sers.put(Locale.classsls);
 
         // starting with 1.7, use compact String for Locale
         sers.put(Locale.classsls);
         
         // then atomic types
         sers.put(AtomicReference.classAtomicReferenceSerializer.class);
         sers.put(AtomicBoolean.classAtomicBooleanSerializer.class);
         sers.put(AtomicInteger.classAtomicIntegerSerializer.class);
         sers.put(AtomicLong.classAtomicLongSerializer.class);
         
         // then other types that need specialized serializers
         sers.put(File.classFileSerializer.class);
         sers.put(Class.classClassSerializer.class);
 
         // And then some stranger types... not 100% they are needed but:
         sers.put(.NullSerializer.class);
         
         return sers.entrySet();
     }
 
     /*
     /**********************************************************
     /* Serializers for atomic types
     /**********************************************************
      */
 
     public final static class AtomicBooleanSerializer
         extends StdScalarSerializer<AtomicBoolean>
     {
         public AtomicBooleanSerializer() { super(AtomicBoolean.classfalse); }
     
         @Override
         public void serialize(AtomicBoolean valueJsonGenerator jgenSerializerProvider provider)
             throws IOExceptionJsonGenerationException
         {
             jgen.writeBoolean(value.get());
         }
     
         @Override
         public JsonNode getSchema(SerializerProvider providerType typeHint)
         {
             return createSchemaNode("boolean"true);
         }
         
         @Override
         public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitorJavaType typeHint)
                 throws JsonMappingException
         {
             visitor.expectBooleanFormat(typeHint);
         }
     }
     
     public final static class AtomicIntegerSerializer
         extends StdScalarSerializer<AtomicInteger>
     {
         public AtomicIntegerSerializer() { super(AtomicInteger.classfalse); }
     
         @Override
         public void serialize(AtomicInteger valueJsonGenerator jgenSerializerProvider provider)
             throws IOExceptionJsonGenerationException
        {
            jgen.writeNumber(value.get());
        }
    
        @Override
        public JsonNode getSchema(SerializerProvider providerType typeHint)
        {
            return createSchemaNode("integer"true);
        }
        
        @Override
        public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitorJavaType typeHint)
                throws JsonMappingException
        {
            JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint);
            if (v2 != null) {
                v2.numberType(..);
            }
        }
    }
    public final static class AtomicLongSerializer
        extends StdScalarSerializer<AtomicLong>
    {
        public AtomicLongSerializer() { super(AtomicLong.classfalse); }
    
        @Override
        public void serialize(AtomicLong valueJsonGenerator jgenSerializerProvider provider)
            throws IOExceptionJsonGenerationException
        {
            jgen.writeNumber(value.get());
        }
    
        @Override
        public JsonNode getSchema(SerializerProvider providerType typeHint)
        {
            return createSchemaNode("integer"true);
        }
        
        @Override
        public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitorJavaType typeHint)
                throws JsonMappingException
        {
            JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint);
            if (v2 != null) {
                v2.numberType(..);
            }
        }
    }
    
    public final static class AtomicReferenceSerializer
        extends StdSerializer<AtomicReference<?>>
    {
        public AtomicReferenceSerializer() { super(AtomicReference.classfalse); }
        @Override
        public void serialize(AtomicReference<?> valueJsonGenerator jgenSerializerProvider provider)
            throws IOExceptionJsonGenerationException
        {
            provider.defaultSerializeValue(value.get(), jgen);
        }
        @Override
        public JsonNode getSchema(SerializerProvider providerType typeHint)
        {
            return createSchemaNode("any"true);
        }
        
        @Override
        public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitorJavaType typeHint)
                throws JsonMappingException
        {
            visitor.expectAnyFormat(typeHint);
        }
    }
New to GrepCode? Check out our FAQ X