[
https://issues.apache.org/jira/browse/JOHNZON-153?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16329160#comment-16329160
]
Dirk Rudolph edited comment on JOHNZON-153 at 1/17/18 6:40 PM:
---------------------------------------------------------------
The issue with JsonString is, that its getString() method is called (once) in
[JsonGeneratorImpl#writeJsonValue(java.lang.String,
javax.json.JsonValue)|https://github.com/apache/johnzon/blob/master/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java#L203]
and so the entire String has to be in memory. I'm working directly with the
core APIs (actually javax.json) not using any binding. How would I implement a
Serializer there?
Ok it looks like this is not even possible with javax.json API. In the Javadoc
of [JsonValue7https://docs.oracle.com/javaee/7/api/javax/json/JsonValue.html]
it says:
{quote}
A JSON value is one of the following: an object (JsonObject), an array
(JsonArray), a number (JsonNumber), a string (JsonString), true
(JsonValue.TRUE), false (JsonValue.FALSE), or null (JsonValue.NULL).
{quote}
so JsonValue is not meant to be implemented implementation specific without
also implementing one of the specific types.
was (Author: diru):
The issue with JsonString is, that its getString() method is called (once) in
[JsonGeneratorImpl#writeJsonValue(java.lang.String,
javax.json.JsonValue)|https://github.com/apache/johnzon/blob/master/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java#L203]
and so the entire String has to be in memory. I'm working directly with the
core APIs (actually javax.json) not using any binding. How would I implement a
Serializer there?
> Support streaming String values using Readable
> ----------------------------------------------
>
> Key: JOHNZON-153
> URL: https://issues.apache.org/jira/browse/JOHNZON-153
> Project: Johnzon
> Issue Type: Improvement
> Components: Core
> Reporter: Dirk Rudolph
> Priority: Major
>
> Currently there are 2 ways writing a String value to JsonGenerator:
> # using {{JsonGenerator#write(java.lang.String, javax.json.JsonValue)}} and
> {{JsonGenerator#write(javax.json.JsonValue)}} respectively or
> # using {{JsonGenerator#write(java.lang.String, java.lang.String)}} and
> {{JsonGenerator#write(java.lang.String)}} respectively
> where in the former case {{JsonValue}} has to be a {{JsonString}} otherwise a
> ClassCastException will be thrown in
> [JsonGeneratorImpl#writeJsonValue(java.lang.String,
> javax.json.JsonValue)|https://github.com/apache/johnzon/blob/master/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java#L203].
> It would be great to change that implementation detail so that a consumer can
> implement its own implementation of {{JsonValue}} with {{ValueType#STRING}}
> but working with {{Reader}} internally so that not the entire String is kept
> in memory.
> The use case behind that I use johonzon to write a solr-json formatted list
> of update commands for solr and want to use tika to parse (potentially huge)
> files into plain text sending them as individual field in my json object.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)