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

IllegalAccessError when trying to serialize java.util.Calendar #54

Closed
GoogleCodeExporter opened this issue Sep 10, 2015 · 1 comment
Closed

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

1. Add the code:

Calendar rightNow = Calendar.getInstance();
Map<String,Object> myMap = new HashMap<>();
myMap.put("myDate",rightNow);
System.out.println("The JSON Object: " + JSONObject.toJSONString(myMap));

2. Build : mvn clean package
3. And execute: java -jar target/my-app-1.0-SNAPSHOT.jar

I created a github repo with the code to show you the problem:

https://github.com/jmaslibre/jsmart-test

To reproduce the problem using it:

1. git clone git@github.com:jmaslibre/jsmart-test.git
2. cd cd jsmart-test/
3. mvn clean package
4. java -jar target/my-app-1.0-SNAPSHOT.jar

What is the expected output? What do you see instead?

The JSON Object: <json represantation of the object>

Instead I get:

-----------------------------------
Exception in thread "main" java.lang.IllegalAccessError: tried to access field 
java.util.Calendar.time from class 
net.minidev.asm.java.util.GregorianCalendarAccAccess
    at net.minidev.asm.java.util.GregorianCalendarAccAccess.get(Unknown Source)
    at net.minidev.json.reader.BeansWriterASM.writeJSONString(BeansWriterASM.java:21)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:596)
    at net.minidev.json.reader.JsonWriter.writeJSONKV(JsonWriter.java:392)
    at net.minidev.json.reader.JsonWriter$7.writeJSONString(JsonWriter.java:145)
    at net.minidev.json.reader.JsonWriter$7.writeJSONString(JsonWriter.java:128)
    at net.minidev.json.JSONObject.writeJSON(JSONObject.java:174)
    at net.minidev.json.JSONObject.toJSONString(JSONObject.java:74)
    at net.minidev.json.JSONObject.toJSONString(JSONObject.java:58)
    at com.mycompany.app.App.main(App.java:21)
---------------------------------------------------------


What version of the product are you using? On what operating system?

I am currently using: Java version: 1.7.0_67, vendor: Oracle Corporation, 
Apache Maven 3.0.5 in Debian Gnu/Linux

I tested with json-smart <version>2.1.1</version>,

and also cloned the repository:
  https://github.com/netplex/json-smart-v2
and buid the using the latest version there: 

392619dda5c53a25b64abe101299f9d263f894e6


Please provide any additional information below.

If you need any more information please let me know.

Thanks for your work in json-smart.

Original issue reported on code.google.com by jmasli...@gmail.com on 26 Mar 2015 at 5:38

@GoogleCodeExporter
Copy link
Author

You have to register Calandar Type to make it serialisable.

JSONValue.registerWriter(Calendar.class, new JsonWriterI<Calendar>() {
// serialisation code.
}) {

Original comment by uriel.chemouni on 29 Jul 2015 at 2:36

  • Changed state: WontFix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant