nillable = false @XmlElement все равно принимает значения NULL Java - PullRequest
0 голосов
/ 05 ноября 2018

Несмотря на то, что я определил @XmlElement с помощью nillable = false и required = true, веб-служба все еще принимает нулевые значения для данного элемента.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CompanyPreference")

public class CompanyPreference {
    public CompanyPreference() {
        super();
    }

    @XmlElement(nillable = false, required = true)
    private String preferenceName;
    @XmlElement(nillable = false, required = true)
    private String preferenceType;
              .
              .
              .

Тогда в моем веб-сервисе

@POST
@SecureIt
@Consumes(value = { MediaType.APPLICATION_JSON })
@Produces(value = { MediaType.APPLICATION_JSON })
@Path("/preferences")
@ApiOperation(value = "Update Company Preferences", response = DefaultResponse.class, authorizations = { @Authorization(value="Bearer") })
public Response savePreferences(CompanyPreference[] companyPreferences, //This is the array
                                @Context ContainerRequestContext crc) throws ResponseError {

Массив настроек, которые я передаю

[
  {
    "preferenceName": null,
    "preferenceType": null
  }
]

Почему я все еще могу передать пустые значения в моем объекте и получить успешный ответ? Я что-то упустил?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...