Giter Site home page Giter Site logo

Comments (9)

nmorel avatar nmorel commented on July 29, 2024

Does this work on regular Jackson ?
I never tried to support 2D arrays so it's not surprising it does not work :p

As a workaround, can you try to create your own deserializer for this ?
Using the documentation here : https://github.com/nmorel/gwt-jackson/wiki/Custom-serializers-and-deserializers

I did a quick test, it seems to work.
In your configuration, you add this :

type( String[][].class ).deserializer( MyString2DArrayDeserializer.class );

And the deserializer can look like this :

public class MyString2DArrayDeserializer extends JsonDeserializer<String[][]> {

    @Override
    protected String[][] doDeserialize( JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params ) {

        List<List<String>> res = new ArrayList<List<String>>();

        reader.beginArray();
        while ( JsonToken.END_ARRAY != reader.peek() ) {
            List<String> list = new ArrayList<String>();
            reader.beginArray();
            while ( JsonToken.END_ARRAY != reader.peek() ) {
                list.add( reader.nextString() );
            }
            reader.endArray();
            res.add( list );
        }
        reader.endArray();

        if ( res.isEmpty() ) {
            return new String[0][0];
        }

        String[][] trueRes = new String[res.size()][res.get( 0 ).size()];
        int i = 0;
        for ( List<String> list : res ) {
            int j = 0;
            for ( String s : list ) {
                trueRes[i][j++] = s;
            }
            i++;
        }
        return trueRes;
    }
}

from gwt-jackson.

DanielCloudCredo avatar DanielCloudCredo commented on July 29, 2024

Thanks for the very prompt response! I'll give this a try.

I can confirm 2D arrays work in regular Jackson, 1.9.7 and 2.3.2

from gwt-jackson.

DanielCloudCredo avatar DanielCloudCredo commented on July 29, 2024

Hi - I had a problem deserializing nulls into a 2D string array. I'm not sure if the bug is particular to 2D arrays or a general issue, but I can load the same data in Jackson just fine.

java.lang.IllegalStateException: Expected a string but was NULL at line 1 column 154

The line/column reference above is talking about the source JSON data where the first null occurs.

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

Instead of reader.nextString(), try StringJsonDeserializer.getInstance().deserialize(reader, ctx, params). It will take care of the null value.

Or wait for the next release that should come soon. (at least the snapshot)

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

The 0.4.1-SNAPSHOT snapshot is available. Can you give it a try ?
If it works for you, I'll release the 0.4.1.

from gwt-jackson.

DanielCloudCredo avatar DanielCloudCredo commented on July 29, 2024

Thanks - I should get a chance to try this tonight or tomorrow.

from gwt-jackson.

DanielCloudCredo avatar DanielCloudCredo commented on July 29, 2024

Hi,

I just had the chance to try 0.4.1-SNAPSHOT, and I'm still getting the same error I'm afraid.

GwtApplication: exception: Couldn't deserialize map [newGfxMap] java.lang.IllegalStateException: Expected a string but was NULL at line 1 column 154

Data snippet:

{"name":"New Map","graphicsPackId":"mxxxxxxGfxPack.json","tileIds":[["1","19","19","19","19","19","19","19","19","19","19","19","19","19","19"],["1",null,null,null,null...

from gwt-jackson.

nmorel avatar nmorel commented on July 29, 2024

Did you remove the workaround with the custom deserializer ?
And you can try the 0.5.0

from gwt-jackson.

DanielCloudCredo avatar DanielCloudCredo commented on July 29, 2024

Ha - you pre-empted my absent-mindedness! I will remove that and try again :)

from gwt-jackson.

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.