johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernd Gutjahr (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (JOHNZON-195) JsonWriter.write(JsonValue) fails with simple values (strings, numbers, booleans)
Date Thu, 22 Nov 2018 07:15:00 GMT

     [ 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)

Mime
View raw message