org.dominokit.jackson.ServerJacksonJsonSerializerParameters Maven / Gradle / Ivy
/*
* 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 org.dominokit.jackson;
import static java.util.Objects.nonNull;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.time.ZoneId;
import java.util.HashSet;
import java.util.Set;
import org.dominokit.jackson.ser.bean.IdentitySerializationInfo;
import org.dominokit.jackson.ser.bean.TypeSerializationInfo;
/**
* This class includes parameters defined through properties annotations like {@link
* com.fasterxml.jackson.annotation.JsonFormat}. They are specific to one {@link
* org.dominokit.jackson.JsonSerializer} and that's why they are not contained inside {@link
* org.dominokit.jackson.JsonSerializationContext}.
*/
@GwtIncompatible
public final class ServerJacksonJsonSerializerParameters implements JsonSerializerParameters {
/** Constant DEFAULT
*/
public static final JsonSerializerParameters DEFAULT =
new ServerJacksonJsonSerializerParameters();
/**
* Datatype-specific additional piece of configuration that may be used to further refine
* formatting aspects. This may, for example, determine low-level format String used for {@link
* java.util.Date} serialization; however, exact use is determined by specific {@link
* JsonSerializer}
*/
private String pattern;
/**
* Structure to use for serialization: definition of mapping depends on datatype, but usually has
* straight-forward counterpart in data format (JSON). Note that commonly only a subset of shapes
* is available; and if 'invalid' value is chosen, defaults are usually used.
*/
private Shape shape = Shape.ANY;
/** Locale to use for serialization (if needed). */
private String locale;
/** Timezone to use for serialization (if needed). */
private ZoneId timezone;
/** Names of properties to ignore. */
private Set ignoredProperties;
/** Inclusion rule to use. */
private Include include;
/** Bean identity informations */
private IdentitySerializationInfo identityInfo;
/** Bean type informations */
private TypeSerializationInfo typeInfo;
/** If true, all the properties of an object will be serialized inside the current object. */
private boolean unwrapped = false;
public ServerJacksonJsonSerializerParameters() {}
public ServerJacksonJsonSerializerParameters(JsonSerializerParameters jsonSerializerParameters) {
this.identityInfo = jsonSerializerParameters.getIdentityInfo();
this.ignoredProperties = jsonSerializerParameters.getIgnoredProperties();
this.include = jsonSerializerParameters.getInclude();
this.locale = jsonSerializerParameters.getLocale();
this.pattern = jsonSerializerParameters.getPattern();
this.shape = jsonSerializerParameters.getShape();
if (nonNull(jsonSerializerParameters.getTimezone())) {
this.timezone = (ZoneId) jsonSerializerParameters.getTimezone();
}
this.typeInfo = jsonSerializerParameters.getTypeInfo();
this.unwrapped = jsonSerializerParameters.isUnwrapped();
}
/**
* {@inheritDoc}
*
* Getter for the field pattern
.
*/
@Override
public String getPattern() {
return pattern;
}
/**
* {@inheritDoc}
*
*
Setter for the field pattern
.
*/
@Override
public JsonSerializerParameters setPattern(String pattern) {
this.pattern = pattern;
return this;
}
/**
* {@inheritDoc}
*
*
Getter for the field shape
.
*/
@Override
public Shape getShape() {
return shape;
}
/**
* {@inheritDoc}
*
*
Setter for the field shape
.
*/
@Override
public JsonSerializerParameters setShape(Shape shape) {
this.shape = shape;
return this;
}
/**
* {@inheritDoc}
*
*
Getter for the field locale
.
*/
@Override
public String getLocale() {
return locale;
}
/**
* {@inheritDoc}
*
*
Setter for the field locale
.
*/
@Override
public JsonSerializerParameters setLocale(String locale) {
this.locale = locale;
return this;
}
/**
* {@inheritDoc}
*
*
Getter for the field timezone
.
*/
@Override
public ZoneId getTimezone() {
return timezone;
}
/**
* {@inheritDoc}
*
*
Setter for the field timezone
.
*/
@Override
public JsonSerializerParameters setTimezone(Object timezone) {
this.timezone = (ZoneId) timezone;
return this;
}
/**
* {@inheritDoc}
*
*
Getter for the field ignoredProperties
.
*/
@Override
public Set getIgnoredProperties() {
return ignoredProperties;
}
/**
* {@inheritDoc}
*
* addIgnoredProperty
*/
@Override
public JsonSerializerParameters addIgnoredProperty(String ignoredProperty) {
if (null == ignoredProperties) {
ignoredProperties = new HashSet();
}
ignoredProperties.add(ignoredProperty);
return this;
}
/**
* {@inheritDoc}
*
* Getter for the field include
.
*/
@Override
public Include getInclude() {
return include;
}
/**
* {@inheritDoc}
*
*
Setter for the field include
.
*/
@Override
public JsonSerializerParameters setInclude(Include include) {
this.include = include;
return this;
}
/**
* {@inheritDoc}
*
*
Getter for the field identityInfo
.
*/
@Override
public IdentitySerializationInfo getIdentityInfo() {
return identityInfo;
}
/**
* {@inheritDoc}
*
*
Setter for the field identityInfo
.
*/
@Override
public JsonSerializerParameters setIdentityInfo(IdentitySerializationInfo identityInfo) {
this.identityInfo = identityInfo;
return this;
}
/**
* {@inheritDoc}
*
*
Getter for the field typeInfo
.
*/
@Override
public TypeSerializationInfo getTypeInfo() {
return typeInfo;
}
/**
* {@inheritDoc}
*
*
Setter for the field typeInfo
.
*/
@Override
public JsonSerializerParameters setTypeInfo(TypeSerializationInfo typeInfo) {
this.typeInfo = typeInfo;
return this;
}
/**
* {@inheritDoc}
*
*
isUnwrapped
*/
@Override
public boolean isUnwrapped() {
return unwrapped;
}
/**
* {@inheritDoc}
*
*
Setter for the field unwrapped
.
*/
@Override
public JsonSerializerParameters setUnwrapped(boolean unwrapped) {
this.unwrapped = unwrapped;
return this;
}
}