Skip to main content

[json-processing-spec users] Re: JSON builder improvements

  • From: Eugen Cepoi < >
  • To:
  • Subject: [json-processing-spec users] Re: JSON builder improvements
  • Date: Sun, 9 Dec 2012 15:10:38 +0100

It looks OK. I am fine with both approaches.
If the builder api is made of classes provided by the spec (I mean that there will be no other impl), I think it could make sense to have JsonObject/Array/number/string as public final classes, instead of actual interfaces?

Eugen


2012/12/9 Jitendra Kotamraju < " target="_blank"> >
On 12/7/12 3:17 PM, Eugen Cepoi wrote:
The downside I see here is that it prevents from using other implementations. It is also not clear how a JsonObjectBuilder would be used in the enclosing builder to produce a JsonObject (without a end method).
This is what I have implemented for JsonObjectBuilder, similarly JsonArrayBuilder impl. IMO, this is much cleaner than the current impl.

public class JsonObjectBuilder {
    private final Map<String, JsonValue> valueMap;

    public JsonObjectBuilder() {
        this.valueMap = new LinkedHashMap<String, JsonValue>();
    }

    public JsonObjectBuilder add(String name, JsonValue value) {
        valueMap.put(name, value);
        return this;
    }

    public JsonObjectBuilder add(String name, String value) {
        valueMap.put(name, new JsonStringImpl(value));
        return this;
    }

    ...

    public JsonObjectBuilder add(String name, JsonObjectBuilder builder) {
        valueMap.put(name, builder.build());
        return this;
    }

    public JsonObjectBuilder add(String name, JsonArrayBuilder builder) {
        valueMap.put(name, builder.build());
        return this;
    }

    public JsonObject build() {
        return new JsonObjectImpl(valueMap);

    }
}

I think that people are getting used to the begin().add().end() style (due to other existing libraries).
He says that in the current proposal, the structure is encoded in the method names, but not the
syntax of the _expression_. I hope users like this approach better as it is simpler.

Jitu

Eugen

2012/12/8 Jitendra Kotamraju < " target="_blank"> >
http://java.net/jira/browse/JSON_PROCESSING_SPEC-36

Would like to close the issue with the suggested improvements

Jitu





[json-processing-spec users] JSON builder improvements

Jitendra Kotamraju 12/07/2012

[json-processing-spec users] Re: JSON builder improvements

Eugen Cepoi 12/07/2012

[json-processing-spec users] Re: JSON builder improvements

Jitendra Kotamraju 12/09/2012

[json-processing-spec users] Re: JSON builder improvements

Eugen Cepoi 12/09/2012

[json-processing-spec users] Re: JSON builder improvements

Jitendra Kotamraju 12/10/2012
 
 
Close
loading
Please Confirm
Close