Class JsonBuilder
- java.lang.Object
-
- de.hybris.platform.integrationservices.util.JsonBuilder
-
public class JsonBuilder extends java.lang.ObjectA helper to build a string in JSON format.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringbuild()static JsonBuilderjson()Creates new instance of this builder.JsonBuilderwithCode(java.lang.String code)Specifies field named "code" for the JSON output.JsonBuilderwithField(java.lang.String field, boolean value)Specifies field value for the JSON output.JsonBuilderwithField(java.lang.String field, JsonBuilder builder)Specifies field value for the JSON output.JsonBuilderwithField(java.lang.String field, java.lang.Character value)Specifies a character field value for the JSON output.JsonBuilderwithField(java.lang.String field, java.lang.Number number)Specifies field value for the JSON output.JsonBuilderwithField(java.lang.String field, java.lang.String value)Specifies field value for the JSON output.JsonBuilderwithField(java.lang.String field, java.util.Collection<?> values)Specifies field value for the JSON output.JsonBuilderwithField(java.lang.String field, java.util.Date date)Specifies date field value for the JSON output.JsonBuilderwithFieldValues(java.lang.String field, java.lang.Object... values)Specifies field value for the JSON output.JsonBuilderwithId(java.lang.String id)Specifies field named "id" for the JSON output.JsonBuilderwithLocalizedAttributes(java.util.Map<java.lang.String,java.lang.String>... attributes)Specifies the localized attributes for the JSON output.
-
-
-
Method Detail
-
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(java.lang.String code)
Specifies field named "code" for the JSON output. This is the same as callingwithField("code", code)- Parameters:
code- value for the "code" field- Returns:
- a builder with the field specified
-
withId
public JsonBuilder withId(java.lang.String id)
Specifies field named "id" for the JSON output. This is the same as callingwithField("id", code)- Parameters:
id- value for the "id" field- Returns:
- a builder with the field specified
-
withField
public JsonBuilder withField(java.lang.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,addressin{"address": {...}}builder- nested JSON object to be used as value for the field- Returns:
- a builder with the field specified.
-
withField
public JsonBuilder withField(java.lang.String field, java.lang.Number number)
Specifies field value for the JSON output.- Parameters:
field- name of the JSON field, which prints before the ":" separator. For example,addressin{"address": {...}}number- numeric value for the field- Returns:
- a builder with the field specified.
-
withField
public JsonBuilder withField(java.lang.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,addressin{"address": {...}}value- boolean value for the field- Returns:
- a builder with the field specified.
-
withField
public JsonBuilder withField(java.lang.String field, java.util.Date date)
Specifies date field value for the JSON output.- Parameters:
field- name of the JSON field, which prints before the ":" separator. For example,addressin{"address": {...}}date- date value for the field- Returns:
- a builder with the field specified.
-
withFieldValues
public JsonBuilder withFieldValues(java.lang.String field, java.lang.Object... values)
Specifies field value for the JSON output.- Parameters:
field- name of the JSON field, which prints before the ":" separator. For example,reviewsin{"reviews": [...]}values- a collection of values for the field- Returns:
- a builder with the field specified.
-
withField
public JsonBuilder withField(java.lang.String field, java.util.Collection<?> values)
Specifies field value for the JSON output.- Parameters:
field- name of the JSON field, which prints before the ":" separator. For example,reviewsin{"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(java.lang.String field, java.lang.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,countryin{"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(java.lang.String field, java.lang.String value)
Specifies field value for the JSON output.- Parameters:
field- name of the JSON field, which prints before the ":" separator. For example,countryin{"country": "USA"}value- value of the JSON field, which prints after the ":" separator. For example,USAin{"country": "USA"}- Returns:
- a builder with the field specified.
-
withLocalizedAttributes
@SafeVarargs public final JsonBuilder withLocalizedAttributes(java.util.Map<java.lang.String,java.lang.String>... attributes)
Specifies the localized attributes for the JSON output.- Parameters:
attributes- An array ofMaps 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 java.lang.String build()
-
-