You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Bernd Gutjahr (JIRA)" <ji...@apache.org> on 2018/11/22 07:15:00 UTC

[jira] [Updated] (JOHNZON-195) JsonWriter.write(JsonValue) fails with simple values (strings, numbers, booleans)

     [ https://issues.apache.org/jira/browse/JOHNZON-195?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bernd Gutjahr updated JOHNZON-195:
----------------------------------
    Description: 
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 have created this pull request: [https://github.com/apache/johnzon/pull/32]

 

 

 

 

  was:
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.

 

 

 


> 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
>            Priority: Minor
>         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 have created this pull request: [https://github.com/apache/johnzon/pull/32]
>  
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)