it.cnr.iit.jscontact.tools.dto.LanguagePref Maven / Gradle / Ivy
/*
* Copyright (C) 2020 Consiglio Nazionale delle Ricerche
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package it.cnr.iit.jscontact.tools.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import it.cnr.iit.jscontact.tools.constraints.BooleanMapConstraint;
import it.cnr.iit.jscontact.tools.constraints.LanguageTagConstraint;
import it.cnr.iit.jscontact.tools.dto.deserializers.ContextsDeserializer;
import it.cnr.iit.jscontact.tools.dto.interfaces.HasContexts;
import it.cnr.iit.jscontact.tools.dto.interfaces.IdMapValue;
import it.cnr.iit.jscontact.tools.dto.interfaces.IsIANAType;
import it.cnr.iit.jscontact.tools.dto.serializers.ContextsSerializer;
import lombok.*;
import lombok.experimental.SuperBuilder;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Map;
/**
* Class mapping the LanguagePref type as defined in section 2.3.4 of [RFC9553].
*
* @see Section 2.3.4 of RFC9553
* @author Mario Loffredo
*/
@JsonPropertyOrder({"@type", "language", "contexts","pref"})
@JsonInclude(JsonInclude.Include.NON_NULL)
@SuperBuilder
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class LanguagePref extends AbstractJSContactType implements IdMapValue, IsIANAType, Serializable, HasContexts {
@Pattern(regexp = "LanguagePref", message="invalid @type value in LanguagePref")
@JsonProperty("@type")
@Builder.Default
String _type = "LanguagePref";
@NotNull(message = "language is missing in LanguagePref")
@NonNull
@LanguageTagConstraint
String language;
@JsonSerialize(using = ContextsSerializer.class)
@JsonDeserialize(using = ContextsDeserializer.class)
@BooleanMapConstraint(message = "invalid Map contexts in LanguagePref - Only Boolean.TRUE allowed")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Map contexts;
@Min(value=1, message = "invalid pref in LanguagePref - value must be greater or equal than 1")
@Max(value=100, message = "invalid pref in LanguagePref - value must be less or equal than 100")
Integer pref;
}