Giter Club home page Giter Club logo

Comments (3)

jdereg avatar jdereg commented on August 23, 2024 1

Looking into this.

from json-io.

raubv0gel avatar raubv0gel commented on August 23, 2024

@jdereg, pardon, but do you have any updates on this issue?

from json-io.

jdereg avatar jdereg commented on August 23, 2024

Found the issues - there are two of them, one yours, one json-io. The json-io issue has an easy work around (I'll put a fix anyway). This particular method advertises that you can pass in null for WriteOptions. Turns out that is not the case and you get an NPE.

So add a proper WriteOptions at the end (instead of null for now), like this:
JsonIo.toString(baos, "🙊🙉🙈", new WriteOptionsBuilder().build());

Now, it will still fail for you because toByteArray() on ByteArray does not support the syntax you are using. You have to convert the ByteArrayOutputStream to a byte[] first, and then create the String from that byte[].

@Test
void testUnicodeChars() throws Exception
{
    String monkeys = "\uD83D\uDE4A\uD83D\uDE49\uD83D\uDE48";
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JsonIo.toJson(baos, monkeys, new WriteOptionsBuilder().build());
    String json = baos.toString();    // Good
    System.out.println("json = " + json);
    // String json = new String(baos.toByteArray(), StandardCharsets.UTF_8);   // inefficient
    // String json = baos.toString(StandardCharsets.UTF_8);   // invalid
}

So this will get you going now. I have a fix coming out for the NPE on null writeOptions.

from json-io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.