All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.nmorel.gwtjackson.client.AbstractConfiguration Maven / Gradle / Ivy

Go to download

gwt-jackson is a GWT JSON serializer/deserializer mechanism based on Jackson annotations

There is a newer version: 0.15.4
Show newest version
/*
 * Copyright 2013 Nicolas Morel
 *
 * 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.github.nmorel.gwtjackson.client;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.github.nmorel.gwtjackson.client.deser.map.key.KeyDeserializer;
import com.github.nmorel.gwtjackson.client.ser.map.key.KeySerializer;

/**
 * 

Abstract AbstractConfiguration class.

* * @author Nicolas Morel * @version $Id: $ */ public abstract class AbstractConfiguration { public class PrimitiveTypeConfiguration { private final Class type; private PrimitiveTypeConfiguration( Class type ) { this.type = type; } public PrimitiveTypeConfiguration serializer( Class serializer ) { mapTypeToSerializer.put( type, serializer ); return this; } public PrimitiveTypeConfiguration deserializer( Class deserializer ) { mapTypeToDeserializer.put( type, deserializer ); return this; } } public class TypeConfiguration { private final Class type; private TypeConfiguration( Class type ) { this.type = type; } public TypeConfiguration serializer( Class serializer ) { mapTypeToSerializer.put( type, serializer ); return this; } public TypeConfiguration deserializer( Class deserializer ) { mapTypeToDeserializer.put( type, deserializer ); return this; } } public class KeyTypeConfiguration { private final Class type; private KeyTypeConfiguration( Class type ) { this.type = type; } public KeyTypeConfiguration serializer( Class serializer ) { mapTypeToKeySerializer.put( type, serializer ); return this; } public KeyTypeConfiguration deserializer( Class deserializer ) { mapTypeToKeyDeserializer.put( type, deserializer ); return this; } } private final Map mapTypeToSerializer = new HashMap(); private final Map mapTypeToDeserializer = new HashMap(); private final Map mapTypeToKeySerializer = new HashMap(); private final Map mapTypeToKeyDeserializer = new HashMap(); private final Map mapMixInAnnotations = new HashMap(); private final List whitelist = new ArrayList(); private JsonAutoDetect.Visibility fieldVisibility = JsonAutoDetect.Visibility.DEFAULT; private JsonAutoDetect.Visibility getterVisibility = JsonAutoDetect.Visibility.DEFAULT; private JsonAutoDetect.Visibility isGetterVisibility = JsonAutoDetect.Visibility.DEFAULT; private JsonAutoDetect.Visibility setterVisibility = JsonAutoDetect.Visibility.DEFAULT; private JsonAutoDetect.Visibility creatorVisibility = JsonAutoDetect.Visibility.DEFAULT; /** *

Constructor for AbstractConfiguration.

*/ protected AbstractConfiguration() { configure(); } /** *

primitiveType

* * @param type Type * @return a {@link PrimitiveTypeConfiguration} to configure serializer and/or deserializer for the given primitive type. */ protected PrimitiveTypeConfiguration primitiveType( Class type ) { if ( !type.isPrimitive() ) { throw new IllegalArgumentException( "Type " + type + " is not a primitive. Call type(Class) instead" ); } return new PrimitiveTypeConfiguration( type ); } /** *

type

* * @param type Type * @return a {@link TypeConfiguration} to configure serializer and/or deserializer for the given type. * @param a T object. */ protected TypeConfiguration type( Class type ) { if ( type.isPrimitive() ) { throw new IllegalArgumentException( "Type " + type + " is a primitive. Call primitiveType(Class) instead" ); } return new TypeConfiguration( type ); } /** * Return a {@link KeyTypeConfiguration} to configure key serializer and/or deserializer for the given type. * * @param type a {@link java.lang.Class} object. * @param Type * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration.KeyTypeConfiguration} object. */ protected KeyTypeConfiguration key( Class type ) { if ( type.isPrimitive() ) { throw new IllegalArgumentException( "Primitive types cannot be used as a map's key" ); } return new KeyTypeConfiguration( type ); } /** * Method to use for adding mix-in annotations to use for augmenting * specified class or interface. All annotations from * mixinSource are taken to override annotations * that target (or its supertypes) has. * * @param target Class (or interface) whose annotations to effectively override * @param mixinSource Class (or interface) whose annotations are to * be "added" to target's annotations, overriding as necessary * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration addMixInAnnotations( Class target, Class mixinSource ) { mapMixInAnnotations.put( target, mixinSource ); return this; } /** * Method to add a regex into whitelist. *

* All the types matching whitelist are added to the subtype list of {@link Object} and * {@link Serializable} serializer/deserializer. *

* * @param regex the regex to add * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration whitelist( String regex ) { whitelist.add( regex ); return this; } /** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for fields. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration fieldVisibility( JsonAutoDetect.Visibility visibility ) { this.fieldVisibility = visibility; return this; } /** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for getters. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration getterVisibility( JsonAutoDetect.Visibility visibility ) { this.getterVisibility = visibility; return this; } /** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for boolean getters. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration isGetterVisibility( JsonAutoDetect.Visibility visibility ) { this.isGetterVisibility = visibility; return this; } /** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for setters. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration setterVisibility( JsonAutoDetect.Visibility visibility ) { this.setterVisibility = visibility; return this; } /** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for creators. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration creatorVisibility( JsonAutoDetect.Visibility visibility ) { this.creatorVisibility = visibility; return this; } /** *

configure

*/ protected abstract void configure(); /** *

Getter for the field mapTypeToSerializer.

* * @return a {@link java.util.Map} object. */ public Map getMapTypeToSerializer() { return mapTypeToSerializer; } /** *

Getter for the field mapTypeToDeserializer.

* * @return a {@link java.util.Map} object. */ public Map getMapTypeToDeserializer() { return mapTypeToDeserializer; } /** *

Getter for the field mapTypeToKeySerializer.

* * @return a {@link java.util.Map} object. */ public Map getMapTypeToKeySerializer() { return mapTypeToKeySerializer; } /** *

Getter for the field mapTypeToKeyDeserializer.

* * @return a {@link java.util.Map} object. */ public Map getMapTypeToKeyDeserializer() { return mapTypeToKeyDeserializer; } /** *

Getter for the field mapMixInAnnotations.

* * @return a {@link java.util.Map} object. */ public Map getMapMixInAnnotations() { return mapMixInAnnotations; } /** *

Getter for the field whitelist.

* * @return a {@link java.util.List} object. */ public List getWhitelist() { return whitelist; } /** *

Getter for the field fieldVisibility.

* * @return a {@link com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility} object. */ public Visibility getFieldVisibility() { return fieldVisibility; } /** *

Getter for the field getterVisibility.

* * @return a {@link com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility} object. */ public Visibility getGetterVisibility() { return getterVisibility; } /** *

Getter for the field isGetterVisibility.

* * @return a {@link com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility} object. */ public Visibility getIsGetterVisibility() { return isGetterVisibility; } /** *

Getter for the field setterVisibility.

* * @return a {@link com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility} object. */ public Visibility getSetterVisibility() { return setterVisibility; } /** *

Getter for the field creatorVisibility.

* * @return a {@link com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility} object. */ public Visibility getCreatorVisibility() { return creatorVisibility; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy