Class JsonBuilder

java.lang.Object
de.hybris.platform.integrationservices.util.JsonBuilder

public class JsonBuilder extends Object
A helper to build a string in JSON format.
  • Method Details

    • json

      public static JsonBuilder json()
      Creates new instance of this builder.
      Returns:
      new builder instance, which has no fields specified and results in "{}" JSON when built.
    • withCode

      public JsonBuilder withCode(String code)
      Specifies field named "code" for the JSON output. This is the same as calling withField("code", code)
      Parameters:
      code - value for the "code" field
      Returns:
      a builder with the field specified
    • withId

      public JsonBuilder withId(String id)
      Specifies field named "id" for the JSON output. This is the same as calling withField("id", code)
      Parameters:
      id - value for the "id" field
      Returns:
      a builder with the field specified
    • withField

      public JsonBuilder withField(String field, JsonBuilder builder)
      Specifies field value for the JSON output.
      Parameters:
      field - name of the JSON field, which prints before the ":" separator. For example, address in {"address": {...}}
      builder - nested JSON object to be used as value for the field
      Returns:
      a builder with the field specified.
    • withField

      public JsonBuilder withField(String field, Number number)
      Specifies field value for the JSON output.
      Parameters:
      field - name of the JSON field, which prints before the ":" separator. For example, address in {"address": {...}}
      number - numeric value for the field
      Returns:
      a builder with the field specified.
    • withField

      public JsonBuilder withField(String field, boolean value)
      Specifies field value for the JSON output.
      Parameters:
      field - name of the JSON field, which prints before the ":" separator. For example, address in {"address": {...}}
      value - boolean value for the field
      Returns:
      a builder with the field specified.
    • withField

      public JsonBuilder withField(String field, Date date)
      Specifies date field value for the JSON output.
      Parameters:
      field - name of the JSON field, which prints before the ":" separator. For example, address in {"address": {...}}
      date - date value for the field
      Returns:
      a builder with the field specified.
    • withFieldValues

      public JsonBuilder withFieldValues(String field, Object... values)
      Specifies field value for the JSON output.
      Parameters:
      field - name of the JSON field, which prints before the ":" separator. For example, reviews in {"reviews": [...]}
      values - a collection of values for the field
      Returns:
      a builder with the field specified.
    • withField

      public JsonBuilder withField(String field, Collection<?> values)
      Specifies field value for the JSON output.
      Parameters:
      field - name of the JSON field, which prints before the ":" separator. For example, reviews in {"reviews": [...]}
      values - nested JSON objects to be used as a collection value for the field
      Returns:
      a builder with the field specified.
    • withField

      public JsonBuilder withField(String field, Character value)
      Specifies a character field value for the JSON output.
      Parameters:
      field - name of the JSON field, which prints before the ":" separator. For example, country in {"country": "USA"}
      value - value of the JSON field, which prints after the ":" separator. For example, 'a' in {"char": "a"}
      Returns:
      a builder with the field specified.
    • withField

      public JsonBuilder withField(String field, String value)
      Specifies field value for the JSON output.
      Parameters:
      field - name of the JSON field, which prints before the ":" separator. For example, country in {"country": "USA"}
      value - value of the JSON field, which prints after the ":" separator. For example, USA in {"country": "USA"}
      Returns:
      a builder with the field specified.
    • withLocalizedAttributes

      @SafeVarargs public final JsonBuilder withLocalizedAttributes(Map<String,String>... attributes)
      Specifies the localized attributes for the JSON output.
      Parameters:
      attributes - An array of Maps with the name of the localized attribute as the key, and the localized value as the value
      Returns:
      a builder with the specified localized attributes.
    • build

      public String build()