| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package org.eclipse.parsson; |
| 18 |
|
| 19 |
import org.eclipse.parsson.api.BufferPool; |
| 20 |
import org.eclipse.parsson.api.JsonConfig; |
| 21 |
|
| 22 |
import jakarta.json.*; |
| 23 |
import jakarta.json.stream.JsonGenerator; |
| 24 |
import jakarta.json.stream.JsonGeneratorFactory; |
| 25 |
import jakarta.json.stream.JsonParser; |
| 26 |
import jakarta.json.stream.JsonParserFactory; |
| 27 |
import jakarta.json.spi.JsonProvider; |
| 28 |
import java.io.InputStream; |
| 29 |
import java.io.OutputStream; |
| 30 |
import java.io.Reader; |
| 31 |
import java.io.Writer; |
| 32 |
import java.util.Collection; |
| 33 |
import java.util.Map; |
| 34 |
import java.math.BigDecimal; |
| 35 |
import java.math.BigInteger; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public class JsonProviderImpl extends JsonProvider { |
| 43 |
|
| 44 |
private final BufferPool bufferPool = new BufferPoolImpl(); |
| 45 |
private final JsonContext emptyContext = new JsonContext(null, bufferPool); |
| 46 |
|
| 47 |
@Override |
| 48 |
public JsonGenerator createGenerator(Writer writer) { |
| 49 |
return new JsonGeneratorImpl(writer, emptyContext); |
| 50 |
} |
| 51 |
|
| 52 |
@Override |
| 53 |
public JsonGenerator createGenerator(OutputStream out) { |
| 54 |
return new JsonGeneratorImpl(out, emptyContext); |
| 55 |
} |
| 56 |
|
| 57 |
@Override |
| 58 |
public JsonParser createParser(Reader reader) { |
| 59 |
return new JsonParserImpl(reader, emptyContext); |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public JsonParser createParser(InputStream in) { |
| 64 |
return new JsonParserImpl(in, emptyContext); |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public JsonParserFactory createParserFactory(Map<String, ?> config) { |
| 69 |
return config == null |
| 70 |
? new JsonParserFactoryImpl(emptyContext) |
| 71 |
: new JsonParserFactoryImpl(new JsonContext(config, bufferPool, JsonContext.PROPERTY_BUFFER_POOL)); |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
public JsonGeneratorFactory createGeneratorFactory(Map<String, ?> config) { |
| 76 |
return config == null |
| 77 |
? new JsonGeneratorFactoryImpl(emptyContext) |
| 78 |
: new JsonGeneratorFactoryImpl( |
| 79 |
new JsonContext(config, bufferPool, |
| 80 |
JsonGenerator.PRETTY_PRINTING, |
| 81 |
JsonContext.PROPERTY_BUFFER_POOL)); |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public JsonReader createReader(Reader reader) { |
| 86 |
return new JsonReaderImpl(reader, emptyContext); |
| 87 |
} |
| 88 |
|
| 89 |
@Override |
| 90 |
public JsonReader createReader(InputStream in) { |
| 91 |
return new JsonReaderImpl(in, emptyContext); |
| 92 |
} |
| 93 |
|
| 94 |
@Override |
| 95 |
public JsonWriter createWriter(Writer writer) { |
| 96 |
return new JsonWriterImpl(writer, emptyContext); |
| 97 |
} |
| 98 |
|
| 99 |
@Override |
| 100 |
public JsonWriter createWriter(OutputStream out) { |
| 101 |
return new JsonWriterImpl(out, emptyContext); |
| 102 |
} |
| 103 |
|
| 104 |
@Override |
| 105 |
public JsonWriterFactory createWriterFactory(Map<String, ?> config) { |
| 106 |
return config == null |
| 107 |
? new JsonWriterFactoryImpl(emptyContext) |
| 108 |
: new JsonWriterFactoryImpl( |
| 109 |
new JsonContext(config, bufferPool, |
| 110 |
JsonGenerator.PRETTY_PRINTING, |
| 111 |
JsonContext.PROPERTY_BUFFER_POOL)); |
| 112 |
} |
| 113 |
|
| 114 |
@Override |
| 115 |
public JsonReaderFactory createReaderFactory(Map<String, ?> config) { |
| 116 |
return config == null |
| 117 |
? new JsonReaderFactoryImpl(emptyContext) |
| 118 |
: new JsonReaderFactoryImpl( |
| 119 |
new JsonContext(config, bufferPool, |
| 120 |
JsonConfig.REJECT_DUPLICATE_KEYS, |
| 121 |
jakarta.json.JsonConfig.KEY_STRATEGY, |
| 122 |
JsonContext.PROPERTY_BUFFER_POOL)); |
| 123 |
} |
| 124 |
|
| 125 |
@Override |
| 126 |
public JsonObjectBuilder createObjectBuilder() { |
| 127 |
return new JsonObjectBuilderImpl(emptyContext); |
| 128 |
} |
| 129 |
|
| 130 |
@Override |
| 131 |
public JsonObjectBuilder createObjectBuilder(JsonObject object) { |
| 132 |
return new JsonObjectBuilderImpl(object, emptyContext); |
| 133 |
} |
| 134 |
|
| 135 |
@Override |
| 136 |
public JsonObjectBuilder createObjectBuilder(Map<String, ?> map) { |
| 137 |
return new JsonObjectBuilderImpl(map, emptyContext); |
| 138 |
} |
| 139 |
|
| 140 |
@Override |
| 141 |
public JsonArrayBuilder createArrayBuilder() { |
| 142 |
return new JsonArrayBuilderImpl(emptyContext); |
| 143 |
} |
| 144 |
|
| 145 |
@Override |
| 146 |
public JsonArrayBuilder createArrayBuilder(JsonArray array) { |
| 147 |
return new JsonArrayBuilderImpl(array, emptyContext); |
| 148 |
} |
| 149 |
|
| 150 |
@Override |
| 151 |
public JsonArrayBuilder createArrayBuilder(Collection<?> collection) { |
| 152 |
return new JsonArrayBuilderImpl(collection, emptyContext); |
| 153 |
} |
| 154 |
|
| 155 |
@Override |
| 156 |
public JsonPointer createPointer(String jsonPointer) { |
| 157 |
return new JsonPointerImpl(jsonPointer, emptyContext); |
| 158 |
} |
| 159 |
|
| 160 |
@Override |
| 161 |
public JsonPatchBuilder createPatchBuilder() { |
| 162 |
return new JsonPatchBuilderImpl(emptyContext); |
| 163 |
} |
| 164 |
|
| 165 |
@Override |
| 166 |
public JsonPatchBuilder createPatchBuilder(JsonArray array) { |
| 167 |
return new JsonPatchBuilderImpl(array, emptyContext); |
| 168 |
} |
| 169 |
|
| 170 |
@Override |
| 171 |
public JsonPatch createPatch(JsonArray array) { |
| 172 |
return new JsonPatchImpl(array, emptyContext); |
| 173 |
} |
| 174 |
|
| 175 |
@Override |
| 176 |
public JsonPatch createDiff(JsonStructure source, JsonStructure target) { |
| 177 |
return new JsonPatchImpl(JsonPatchImpl.diff(source, target, emptyContext), emptyContext); |
| 178 |
} |
| 179 |
|
| 180 |
@Override |
| 181 |
public JsonMergePatch createMergePatch(JsonValue patch) { |
| 182 |
return new JsonMergePatchImpl(patch, emptyContext); |
| 183 |
} |
| 184 |
|
| 185 |
@Override |
| 186 |
public JsonMergePatch createMergeDiff(JsonValue source, JsonValue target) { |
| 187 |
return new JsonMergePatchImpl(JsonMergePatchImpl.diff(source, target, emptyContext), emptyContext); |
| 188 |
} |
| 189 |
|
| 190 |
@Override |
| 191 |
public JsonString createValue(String value) { |
| 192 |
return new JsonStringImpl(value); |
| 193 |
} |
| 194 |
|
| 195 |
@Override |
| 196 |
public JsonNumber createValue(int value) { |
| 197 |
return JsonNumberImpl.getJsonNumber(value, emptyContext.bigIntegerScaleLimit()); |
| 198 |
} |
| 199 |
|
| 200 |
@Override |
| 201 |
public JsonNumber createValue(long value) { |
| 202 |
return JsonNumberImpl.getJsonNumber(value, emptyContext.bigIntegerScaleLimit()); |
| 203 |
} |
| 204 |
|
| 205 |
@Override |
| 206 |
public JsonNumber createValue(double value) { |
| 207 |
return JsonNumberImpl.getJsonNumber(value, emptyContext.bigIntegerScaleLimit()); |
| 208 |
} |
| 209 |
|
| 210 |
@Override |
| 211 |
public JsonNumber createValue(BigInteger value) { |
| 212 |
return JsonNumberImpl.getJsonNumber(value, emptyContext.bigIntegerScaleLimit()); |
| 213 |
} |
| 214 |
|
| 215 |
@Override |
| 216 |
public JsonNumber createValue(BigDecimal value) { |
| 217 |
return JsonNumberImpl.getJsonNumber(value, emptyContext.bigIntegerScaleLimit()); |
| 218 |
} |
| 219 |
|
| 220 |
@Override |
| 221 |
public JsonBuilderFactory createBuilderFactory(Map<String, ?> config) { |
| 222 |
return config == null |
| 223 |
? new JsonBuilderFactoryImpl(emptyContext) |
| 224 |
: new JsonBuilderFactoryImpl( |
| 225 |
new JsonContext(config, bufferPool, |
| 226 |
JsonConfig.REJECT_DUPLICATE_KEYS, |
| 227 |
jakarta.json.JsonConfig.KEY_STRATEGY, |
| 228 |
JsonContext.PROPERTY_BUFFER_POOL)); |
| 229 |
} |
| 230 |
|
| 231 |
@Override |
| 232 |
public JsonNumber createValue(Number value) { |
| 233 |
return JsonNumberImpl.getJsonNumber(value, emptyContext.bigIntegerScaleLimit()); |
| 234 |
} |
| 235 |
|
| 236 |
} |