Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve Exception when using List ( java.util.Arrays.asList , java.util.Colletions.emptyList , java.util.Colletions.emptySet , java.util.Colletions.emptyMap) #28

Closed
Arya1112 opened this issue Jan 11, 2017 · 1 comment

Comments

@Arya1112
Copy link

I try to serialize java util collection , but when result of collection from inner class like
method

"java.util.Arrays.asList , java.util.Colletions.emptyList , java.util.Colletions.emptySet , java.util.Colletions.emptyMap"

i got error :

at encoder.java.util.Arrays.ArrayList.encode(ArrayList.java)
at com.jsoniter.output.JsonStream.writeVal(JsonStream.java:276)
at com.jsoniter.output.JsonStream.serialize(JsonStream.java:295)
at com.jsoniter.output.JsonStream.serialize(JsonStream.java:314)
at test.json.datatype.JavaUtilCollectionsJson.main(JavaUtilCollectionsJson.java:28)

My Test Code :

import com.jsoniter.DecodingMode;
import com.jsoniter.JsonIterator;
import com.jsoniter.annotation.JsoniterAnnotationSupport;
import com.jsoniter.output.EncodingMode;
import com.jsoniter.output.JsonStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;


public class JavaUtilCollectionsJson {
    public static void main(String[] args) {
        JsoniterAnnotationSupport.enable();
        JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_STRICTLY);
        JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
        
        List<String> arraysAsList=Arrays.asList(" STRING-1 ", " STRING-2 ", " STRING-3 ");
        try{
            JsonStream.serialize(arraysAsList);
        }
        catch(Throwable t){
            System.out.println("============== ERROR Arrays.asList ===================");
            t.printStackTrace();
            System.out.println("============== End ERROR Arrays.asList ===================");
            
        }

        List<String> emptyList=Collections.emptyList();
        try{
            JsonStream.serialize(emptyList);
        }
        catch(Throwable t){
            System.out.println("============== ERROR Collections.emptyList ===================");
            t.printStackTrace();
            System.out.println("============== End ERROR Collections.emptyList ===================");
        }
        
        
        Set<String> emptySet=Collections.emptySet();
        try{
            JsonStream.serialize(emptySet);
        }
        catch(Throwable t){
            System.out.println("============== ERROR Collections.emptySet ===================");
            t.printStackTrace();
            System.out.println("============== End ERROR Collections.emptySet ===================");
        }        
        
        Map<String,Object> emptyMap=Collections.emptyMap();
        try{
            JsonStream.serialize(emptyMap);
        }
        catch(Throwable t){
            System.out.println("============== ERROR Collections.emptyMap ===================");
            t.printStackTrace();
            System.out.println("============== End ERROR Collections.emptyMap ===================");
        }        
        
    }
}

Thanks

@taowen
Copy link
Contributor

taowen commented Jan 11, 2017

this should be fixed now

@taowen taowen closed this as completed Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants