Ejemplo n.º 1
0
 /**
  * Convert a {@link ISelectableValueHolderCollection} into JSON.<br>
  * The structure is the following one : { "value" : {"value" : "the value", "name" : "the name",
  * "description" : "the description","url" : "the url"} }
  *
  * @param valueHoldersList a collection
  * @return a JSON object
  */
 public static <T> ObjectNode marshallAsJson(List<ISelectableValueHolder<T>> valueHoldersList) {
   ObjectNode valueHoldersAsJson = Json.newObject();
   if (valueHoldersList != null) {
     int order = 0;
     for (ISelectableValueHolder<T> valueHolder : valueHoldersList) {
       valueHoldersAsJson.set(
           String.valueOf(valueHolder.getValue()), marshallAsJson(valueHolder, order));
       order++;
     }
   }
   return valueHoldersAsJson;
 }
Ejemplo n.º 2
0
 /**
  * Convert a {@link ISelectableValueHolder} into JSON.<br>
  * The structure is the following one : {"value" : "the value", "name" : "the name", "description"
  * : "the description","url" : "the url"}
  *
  * @param valueHolder a value holder
  * @return a JSON object
  */
 public static <T> ObjectNode marshallAsJson(ISelectableValueHolder<T> valueHolder, int order) {
   ObjectNode valueHolderAsJson = Json.newObject();
   valueHolderAsJson.put("name", valueHolder.getName());
   valueHolderAsJson.put("order", order);
   valueHolderAsJson.put("value", String.valueOf(valueHolder.getValue()));
   if (valueHolder.getDescription() != null) {
     valueHolderAsJson.put("description", valueHolder.getDescription());
   }
   if (valueHolder.getUrl() != null) {
     valueHolderAsJson.put("url", valueHolder.getUrl());
   }
   return valueHolderAsJson;
 }