com.github.jasminb.jsonapi.SerializationSettings Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsonapi-converter Show documentation
Show all versions of jsonapi-converter Show documentation
JSONAPI-Converter is a library that provides means for integrating with services using JSON API specification.
package com.github.jasminb.jsonapi;
import java.util.ArrayList;
import java.util.List;
/**
* Serialization settings.
*
* @author jbegic
*/
public class SerializationSettings {
private List relationshipIncludes;
private List relationshipExludes;
private Boolean serializeMeta;
private Boolean serializeLinks;
private SerializationSettings() {
// Hide CTOR
}
/**
* Checks if relationship with provided name has been explicitly marked for inclusion in serialized object.
* @param relationshipName {@link String} relationship name
* @return {@link Boolean}
*/
public boolean isRelationshipIncluded(String relationshipName) {
return relationshipIncludes.contains(relationshipName);
}
/**
* Checks if relationship with provided name has been explicitly marked for exclusion in serialized object.
* @param relationshipName {@link String} relationship name
* @return {@link Boolean}
*/
public boolean isRelationshipExcluded(String relationshipName) {
return relationshipExludes.contains(relationshipName);
}
/**
* Returns meta serialization flag.
* @return {@link Boolean}
*/
public Boolean serializeMeta() {
return serializeMeta;
}
/**
* Returns links serialization flag.
* @return {@link Boolean}
*/
public Boolean serializeLinks() {
return serializeLinks;
}
/**
* Serialisation settings builder.
*/
public static class Builder {
private List relationshipIncludes = new ArrayList<>();
private List relationshipExludes = new ArrayList<>();
private Boolean serializeMeta;
private Boolean serializeLinks;
/**
* Explicitly enable relationship serialisation.
* @param relationshipName {@link String} relationship name
* @return {@link Builder}
*/
public Builder includeRelationship(String relationshipName) {
relationshipIncludes.add(relationshipName);
return this;
}
/**
* Explicitly disable relationship serialisation.
* @param relationshipName {@link String} relationship name
* @return {@link Builder}
*/
public Builder excludedRelationships(String relationshipName) {
relationshipExludes.add(relationshipName);
return this;
}
/**
* Enable or disable meta serialization.
* @param flag {@link Boolean} serialization flag
* @return {@link Builder}
*/
public Builder serializeMeta(Boolean flag) {
serializeMeta = flag;
return this;
}
/**
* Enable or disable links serialization.
* @param flag {@link Boolean} serialization flag
* @return {@link Builder}
*/
public Builder serializeLinks(Boolean flag) {
serializeLinks = flag;
return this;
}
/**
* Create new SerialisationSettings instance.
* @return {@link SerializationSettings}
*/
public SerializationSettings build() {
SerializationSettings result = new SerializationSettings();
result.relationshipIncludes = new ArrayList<>(relationshipIncludes);
result.relationshipExludes = new ArrayList<>(relationshipExludes);
result.serializeLinks = serializeLinks;
result.serializeMeta = serializeMeta;
return result;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy