Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions joy-classic-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
<packaging>jar</packaging>
<name>org.leadpony.joy.classic.tests</name>

<properties>
<maven.compiler.release>14</maven.compiler.release>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
18 changes: 16 additions & 2 deletions joy-core/src/main/java/org/leadpony/joy/api/JsonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public interface JsonGenerator extends jakarta.json.stream.JsonGenerator {
String INDENTATION_SIZE = "org.leadpony.joy.api.JsonGenerator.indentationSize";

/**
* Configuration property to use a tab for indentation instead of spaces. The
* value of the property could be anything.
* Configuration property to use a tab for indentation instead of spaces.
* The value of the property could be anything.
* <pre>
* <code>
* Map&lt;String, Object&gt; config = new HashMap&lt;&gt;();
Expand All @@ -53,4 +53,18 @@ public interface JsonGenerator extends jakarta.json.stream.JsonGenerator {
* @since 1.1
*/
String TAB_INDENTATION = "org.leadpony.joy.api.JsonGenerator.tabIndentation";

/**
* Configuration property to indicate that the output of the generator is a
* sequence of JSON values. The value of the property could be anything.
* <pre>
* <code>
* Map&lt;String, Object&gt; config = new HashMap&lt;&gt;();
* config.put(JsonGenerator.VALUE_STREAM, Boolean.TRUE);
* </code>
* </pre>
*
* @since 1.2
*/
String VALUE_STREAM = "org.leadpony.joy.api.JsonGenerator.valueStream";
}
38 changes: 38 additions & 0 deletions joy-core/src/main/java/org/leadpony/joy/api/JsonParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2019-2020 the Joy Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.leadpony.joy.api;

/**
* An extended {@link JsonParser}.
*
* @author leadpony
*/
public interface JsonParser {

/**
* Configuration property to indicate that the input of the parser is a
* sequence of JSON values. The value of the property could be anything.
* <pre>
* <code>
* Map&lt;String, Object&gt; config = new HashMap&lt;&gt;();
* config.put(JsonParser.VALUE_STREAM, Boolean.TRUE);
* </code>
* </pre>
*
* @since 1.2
*/
String VALUE_STREAM = "org.leadpony.joy.api.JsonParser.valueStream";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.leadpony.joy.core;

import static org.leadpony.joy.core.Preconditions.requireNonNull;
Expand All @@ -34,12 +33,19 @@
*/
public abstract class AbstractJsonParserFactory extends ConfigurableFactory implements JsonParserFactory {

private static final String[] SUPPORTED_PROPERTIES = {
org.leadpony.joy.api.JsonParser.VALUE_STREAM
};

final boolean valueStream;

protected AbstractJsonParserFactory(Map<String, ?> properties) {
this(properties, NO_SUPPORTED_PROPERTIES);
this(properties, SUPPORTED_PROPERTIES);
}

protected AbstractJsonParserFactory(Map<String, ?> properties, String[] supported) {
super(properties, supported);
this.valueStream = containsProperty(org.leadpony.joy.api.JsonParser.VALUE_STREAM);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ protected AbstractJsonProvider() {
@Override
public JsonParser createParser(Reader reader) {
requireNonNull(reader, "reader");
return new BasicJsonParser(reader, bufferFactory);
return new BasicJsonParser(reader, bufferFactory, false);
}

@Override
public JsonParser createParser(InputStream in) {
requireNonNull(in, "in");
Reader reader = createStreamReader(in);
return new BasicJsonParser(reader, bufferFactory);
return new BasicJsonParser(reader, bufferFactory, false);
}

@Override
Expand All @@ -88,14 +88,14 @@ public JsonParserFactory createParserFactory(Map<String, ?> config) {
@Override
public JsonGenerator createGenerator(Writer writer) {
requireNonNull(writer, "writer");
return new CompactJsonGenerator(writer, bufferFactory);
return new CompactJsonGenerator(writer, bufferFactory, false);
}

@Override
public JsonGenerator createGenerator(OutputStream out) {
requireNonNull(out, "out");
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
return new CompactJsonGenerator(writer, bufferFactory);
return new CompactJsonGenerator(writer, bufferFactory, false);
}

@Override
Expand All @@ -118,15 +118,15 @@ public JsonReader createReader(InputStream in) {
@Override
public JsonWriter createWriter(Writer writer) {
requireNonNull(writer, "writer");
JsonGenerator generator = new CompactJsonGenerator(writer, bufferFactory);
JsonGenerator generator = new CompactJsonGenerator(writer, bufferFactory, false);
return new JsonWriterImpl(generator);
}

@Override
public JsonWriter createWriter(OutputStream out) {
requireNonNull(out, "out");
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
JsonGenerator generator = new CompactJsonGenerator(writer, bufferFactory);
JsonGenerator generator = new CompactJsonGenerator(writer, bufferFactory, false);
return new JsonWriterImpl(generator);
}

Expand Down Expand Up @@ -202,7 +202,7 @@ public JsonPatch createPatch(JsonArray array) {
* {@inheritDoc}
*
* @throws IllegalArgumentException if the type of {@code target} is not the
* same as {@code source}.
* same as {@code source}.
*/
@Override
public JsonPatch createDiff(JsonStructure source, JsonStructure target) {
Expand Down
Loading