1 package com.fasterxml.jackson.databind.jsonFormatVisitors; 2 3 import com.fasterxml.jackson.databind.BeanProperty; 4 import com.fasterxml.jackson.databind.JavaType; 5 import com.fasterxml.jackson.databind.JsonMappingException; 6 import com.fasterxml.jackson.databind.SerializerProvider; 7 8 /** 9 * Visitor called when properties of a type that maps to JSON Object 10 * are being visited: this usually means POJOs, but sometimes other 11 * types use it too (like {@link java.util.EnumMap}). 12 */ 13 public interface JsonObjectFormatVisitor extends JsonFormatVisitorWithSerializerProvider 14 { 15 /** 16 * Callback method called when a POJO property is being traversed. 17 */ property(BeanProperty writer)18 public void property(BeanProperty writer) throws JsonMappingException; 19 20 /** 21 * Callback method called when a non-POJO property (typically something 22 * like an Enum entry of {@link java.util.EnumMap} type) is being 23 * traversed. With POJOs, {@link #property(BeanProperty)} is called instead. 24 */ property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint)25 public void property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) throws JsonMappingException; 26 optionalProperty(BeanProperty writer)27 public void optionalProperty(BeanProperty writer) throws JsonMappingException; optionalProperty(String name, JsonFormatVisitable handler, JavaType propertyTypeHint)28 public void optionalProperty(String name, JsonFormatVisitable handler, 29 JavaType propertyTypeHint) 30 throws JsonMappingException; 31 32 /** 33 * Default "empty" implementation, useful as the base to start on; 34 * especially as it is guaranteed to implement all the method 35 * of the interface, even if new methods are getting added. 36 */ 37 public static class Base 38 implements JsonObjectFormatVisitor 39 { 40 protected SerializerProvider _provider; 41 Base()42 public Base() { } Base(SerializerProvider p)43 public Base(SerializerProvider p) { _provider = p; } 44 45 @Override getProvider()46 public SerializerProvider getProvider() { return _provider; } 47 48 @Override setProvider(SerializerProvider p)49 public void setProvider(SerializerProvider p) { _provider = p; } 50 51 @Override property(BeanProperty prop)52 public void property(BeanProperty prop) throws JsonMappingException { } 53 54 @Override property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint)55 public void property(String name, JsonFormatVisitable handler, 56 JavaType propertyTypeHint) throws JsonMappingException { } 57 58 @Override optionalProperty(BeanProperty prop)59 public void optionalProperty(BeanProperty prop) throws JsonMappingException { } 60 61 @Override optionalProperty(String name, JsonFormatVisitable handler, JavaType propertyTypeHint)62 public void optionalProperty(String name, JsonFormatVisitable handler, 63 JavaType propertyTypeHint) throws JsonMappingException { } 64 } 65 } 66