Skip navigation links

Package com.veeva.vault.sdk.api.core

This package provides interfaces for common functions and utilities, such as the Debug Log and request context.

See: Description

Package com.veeva.vault.sdk.api.core Description

This package provides interfaces for common functions and utilities, such as the Debug Log and request context.

User-Defined Model

User-defined models (UDMs) are interfaces that are made up of user-defined properties, which can be accessed with getter and setter methods. Once a UDM has been defined, instances of this type can be serialized to JSON. Likewise, JSON can be deserialized to instances of the UDM.

A UDM is a Java interface that extends the UserDefinedModel interface and has the UserDefinedModelInfo annotation as shown below:

  @UserDefinedModelInfo(include = UserDefinedPropertyInclude.NON_NULL)
  public interface DocumentModel extends UserDefinedModel {

      @UserDefinedProperty(include = UserDefinedPropertyInclude.ALWAYS)
      BigDecimal getId();
      void setId(BigDecimal id);

      @UserDefinedProperty(name = "name__v", aliases = {"docName", "documentName"})
      String getName();
      void setName(String name);

      @UserDefinedProperty(defaultValue = "true")
      Boolean getActive();
      void setActive(Boolean active);

      @UserDefinedProperty(defaultValues = {"prod1", "prod2"})
      List<String> getProducts();
       void setProducts(List<String> products);
   }
 
 
The UDM above contains four properties: id, name (which has been renamed to name__v with the name attribute), active, and products. For more detail about the attributes of a user-defined property, please refer to the UserDefinedProperty documentation.

Once a UDM has been defined, create instances of it by using UserDefinedModelService, as shown below:

 
     UserDefinedModelService userDefinedModelService = ServiceLocator.locate(UserDefinedModelService.class);

     DocumentModel documentModel = userDefinedModelService.newUserDefinedModel(DocumentModel.class);
     documentModel.setId(new BigDecimal(1));
     documentModel.setName("newDoc");
 
 
The code above instantiates an empty DocumentModel, and sets its id and name. Note that even though the active property was not explicitly set, it will have been automatically set to true because in its UserDefinedProperty annotation, the defaultValue attribute was used. Similarly, products will have been set to {"prod1", "prod2"} because of the use of the defaultValues attribute.

Now that we have instantiated a DocumentModel, we can send it in JSON form as the body of a HttpRequest by using the HttpRequest.setBody(com.veeva.vault.sdk.api.core.UserDefinedModel) method (see the package-info in com.veeva.vault.sdk.api.http for an example of how HttpRequest is used).

There are several ways that UDMs can be used for deserialization of JSON data. Please refer to the documentation of HttpService.send(com.veeva.vault.sdk.api.http.HttpRequest, java.lang.Class), JsonService.convertToUserDefinedModel(com.veeva.vault.sdk.api.json.JsonObject, java.lang.Class), and the other UDM-related methods in JsonService for more information.

Skip navigation links

Copyright © Veeva Systems 2017–2021. All rights reserved.