Bernd Gutjahr created JOHNZON-195:
-------------------------------------
Summary: JsonWriter.write(JsonValue) fails with simple values
(strings, numbers, booleans)
Key: JOHNZON-195
URL: https://issues.apache.org/jira/browse/JOHNZON-195
Project: Johnzon
Issue Type: Bug
Components: Core
Affects Versions: 1.1.10
Reporter: Bernd Gutjahr
Attachments: johnzon-writer.diff
The following code snipped fails with a JsonGenerationException("Invalid json").
{{ try (JsonWriter jsonWriter = Json.createWriter(System.out))}}
{{ {}}
{{ jsonWriter.write(Json.createValue("hello"));}}
{{ }}}
I would have expected this code to write just the value to the output stream,
e.g. "hello" in the above example. Reading such values via
JsonReader.readValue() works fine and I wanted to write out any kind of values
that have been read before.
As a workaround, I'm currently using the JsonWriter only for types ARRAY and
OBJECT and otherwise just use JsonValue.toString(), but I want to get rid of
such ugly code.
To fix the issue, I would suggest to take my attached patch
(johnzon-writer.diff), where
I have enhanced the unit test JsonWriterImplTest to cover all kinds of values
and then made some changes to JsonGeneratorImpl to get the test working.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)