pdl3 / jsonmarshaller Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/jsonmarshaller
License: Apache License 2.0
Automatically exported from code.google.com/p/jsonmarshaller
License: Apache License 2.0
Allow value types to be annotated with @JsonType(TheType.class) as a
replacement for the repeated @Value(type = TheType.class)
Original issue reported on code.google.com by [email protected]
on 10 Sep 2010 at 11:17
use net.sf.json for basic elements.
JSONArray does not implements any List so
@Entity
public class Settings {
@Value(type = TreeSetType.class)
private SortedSet<Project> projects = new TreeSet<Project>();
}
a user type need more work to trasform JSONArray to a List
Original issue reported on code.google.com by [email protected]
on 15 Oct 2008 at 2:22
What about updating ASM dependencies as long as issue 2 is not fixed?
Original issue reported on code.google.com by [email protected]
on 27 Apr 2010 at 4:15
The {{{@Value}}} annotation is now kept at runtime, no need to read the
bytecode to get its values.
We probably want to create a {{{ValueAccessor}}} providing access to this
annotation in a usefull way.
Original issue reported on code.google.com by [email protected]
on 24 Feb 2008 at 4:55
When trying to unmarshall a Boolean object, if this object is set to null,
a ClassCastEception is thrown.
In the class BooleanDescriptor a check on JSONObject.NULL as given object
is missing.
I made a patch, that fixes the problem.
Original issue reported on code.google.com by [email protected]
on 3 Jun 2008 at 2:18
Attachments:
What steps will reproduce the problem?
System.out.println(
TwoLattes.createMarshaller(Long.class)
.marshallList(asList(123L, 9876543210L))
.toString());
What is the expected output? What do you see instead?
Expected: [123,9876543210]
Actual:
java.lang.IllegalArgumentException: class java.lang.Long is not an entity.
Entities must be annotated with @Entity.
at com.twolattes.json.DescriptorFactory.create(DescriptorFactory.java:30)
at com.twolattes.json.MarshallerImpl.<init>(MarshallerImpl.java:23)
at com.twolattes.json.TwoLattes$Builder.createMarshaller(TwoLattes.java:60)
at com.twolattes.json.TwoLattes.createMarshaller(TwoLattes.java:27)
...
Original issue reported on code.google.com by [email protected]
on 28 Nov 2009 at 10:33
Hi,
This is somewhat of a complicated issue, so let me explain with an example
and then I'll give some references and example code. I've been using
jsonmarshaller with great success and it is a nice package (hoping to see a
1.0 release at some point with the asm stuff removed).
The issue is that both EntitySignatureVistor.java and
ValueAnnotationVisitor.java contain calls to Class.forName(). This works
fine if json-xx.jar is in the same class loader as the application, but
fails if they are in different class loaders.
As an example:
Assume classes C1 and C2 are entities (with @Entity) along with the class
Test. C1 has C2 as a member. Also assume that json-xx.jar is loaded in
classloader CLa and that C1,C2, and Test are all loaded in classloader CLb.
When Test runs, it can successfully marshal C2 just fine; however, it
cannot marshal C1, because it blows up with a ClassNotFound Exception.
Why? Because the json-xx.jar is loaded in CLb and is trying to find class
C2 via a call to Class.forName() in EntitySignatureVistor.java
I've created a sample test case for this to show. Attached is files.tar.
To use, just untar and run the script 'test-noclassloader' -- that works
just fine. Now run the script 'test-classloader' and it blows up. I've
run this on Linux and a Mac.
Here are some ideas and thoughts:
1. Here is a web page that talks about this problem in detail:
http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html?page=1
It exactly describes this issue.
2. Modify the source of jsonmarshaller to not call Class.forName() at all
(can you just get the class by getting the class of the member itself, not
using the name?)
3. Modify the source to use the current thread's context class loader (I
actually hacked the source and got this to work, but it was a hack). You
could use some of the ideas in (1)
4. Modify the source to try to get the class by using the current
Class.forName() and if that fails (throws ClassNotFoundException), then try
Class.forName(name, true, loader) where loader is obtained by
Thread().currentThread().getContextClassLoader() before giving up. This
might be the easiest/best way to deal with this issue. Of course,
applications like the sample one would have to set the current thread's
ContextClassLoader, but at least it would work.
Remember there are 2 places where Class.forName() is called and both need
to be looked at.
I hope this helps. Feel free to contact me if you have questions/issues/...
Jim Stabile
Original issue reported on code.google.com by [email protected]
on 20 Aug 2009 at 6:04
Attachments:
@Entity
class BubbleMe {
@Value int getFoo() { throw new RuntimeException(); }
}
TwoLattes.createMarshaller(BubbleMe.class).marshall(new BubbleMe());
will result in InvocationTargetException instead of RuntimeException.
Original issue reported on code.google.com by [email protected]
on 11 Dec 2009 at 12:14
What steps will reproduce the problem?
1. Create a simple value object class (for instance Money with field
"amount" inside it), with equals implemented as value equals
2. Put 2 instances of your object with same values inside object graph/tree
3. marshall the object graph
What is the expected output? What do you see instead?
You get java.lang.IllegalArgumentException: cyclicity detected
Would like the ability to mark an entity as "valueObject" or something like
that so value equal instances can bypass the cyclicity check.
What version of the product are you using? On what operating system?
Using version 0.10
Please provide any additional information below.
I already implemented this by adding a "valueObject" property on the Entity
annotation and checking this for bypass in the ConcreteEntityDescriptor.
I'm not sure if this would need to be checked in other descriptors. Code
for Entity and ConcreteEntityDescriptor attached.
Original issue reported on code.google.com by [email protected]
on 11 Mar 2008 at 10:14
Attachments:
Supposing the hierarchy
@Entity(subclasses = Leaf) class Top {}
@Entity class Middle extends Top {}
@Entity class Leaf extends Middle {}
the JsonMarshaller should not fail if Middle has no no-arg constructor.
Original issue reported on code.google.com by [email protected]
on 6 Aug 2009 at 10:18
It's sometimes nice, in tests, to initialize an @Entity instance using an
instance initializer. This works for simple @Entity types, but fails for
polymorphic ones.
For example, this works:
@Entity
static class Foo {
@Value Integer bar;
}
TwoLattes.createMarshaller(Foo.class).marshall(new Foo() {{
bar = 3;
}});
...but this doesn't work:
@Entity(discriminatorName = "type", subclasses = Foo2.class)
static class Foo {
@Value Integer bar;
}
@Entity(discriminator = "foo2")
static class Foo2 extends Foo {
@Value Integer baz;
}
TwoLattes.createMarshaller(Foo.class).marshall(new Foo2() {{
bar = 3;
baz = 4;
}});
It produces this error:
java.lang.IllegalArgumentException: Unmarshalled entity of class class
com.SampleTest$1is not a valid subclass entity of class com.SampleTest$Foo
at com.twolattes.json.PolymorphicEntityDescriptor.marshall(PolymorphicEntityDescriptor.java:106)
at com.twolattes.json.PolymorphicEntityDescriptor.marshall(PolymorphicEntityDescriptor.java:12)
at com.twolattes.json.EntityMarshallerImpl.marshall(EntityMarshallerImpl.java:42)
at com.twolattes.json.EntityMarshallerImpl.marshall(EntityMarshallerImpl.java:38)
at com.twolattes.json.EntityMarshallerImpl.marshall(EntityMarshallerImpl.java:17)
When implementing, just need to ensure that the anonymous type declares no
@Value fields or methods and that its immediate superclass is an @Entity class
that has a discriminator.
Original issue reported on code.google.com by [email protected]
on 2 Nov 2012 at 7:05
The entities
@Entity
class HelloWorld {
@Value FooBar<Something> fooBar;
}
@Entity
class FooBar<T> { ..
should be legal.
Original issue reported on code.google.com by [email protected]
on 28 Feb 2008 at 11:50
Entity:
@Entity
class Response {
@Value
public JSONArray data;
@Value
public int timestamp;
} // Response
JSON:
{"data":[["default","E-Mail",false],[25,"Calendar",true],
[26,"Contacts",true],[27,"Tasks",true],[28,"My infostore
folder",true]],"timestamp":1210263232594}
What is the expected output? What do you see instead?
To be able to un-marshall the JSON shown above into some form of Java
object. It results in a ClassCastException because the Marshaller
recognizes the contents of 'data' key as a JSONArray, and then tries to
cast it as such - which then complains that JSONArray is not an Entity
(which it is not). I am un-sure as to the proper way to form a Java object
that can be un-marshalled from this JSON data. I also tried Set<String>
data, Set<JSONArray> data & String data. I am positive that the problem
lies with the type of the variable 'data' in the Response class. How do
you represent a Java Object that can hold a JSONArray of JSONArrays ??
Please provide any additional information below.
For the time being I am just dealing with the server response as a
JSONObject, getting the 'data' key as a String, and creating a JSONArray
from it and working with the information in that manner. This solution is
sub-optimal, and I wonder what suggestions you might have for me.
Original issue reported on code.google.com by [email protected]
on 29 May 2008 at 9:45
Please, deploy your lib to some of the public maven repos
Original issue reported on code.google.com by [email protected]
on 20 Aug 2009 at 3:14
Using the @Entity tag with byte or Byte does not work. Changing to short,
int, or long works fine.
Code:
Light.java
------------
import com.twolattes.json.*;
@Entity
public class Light {
@Value(name="ballastTemp")
private byte mBallastTemp;
public Light() {
}
}
Marsh.java
----------
import com.twolattes.json.*;
public class Marsh {
public static void main(String[] args) throws Exception {
Marshaller<Light> m
Marshaller<Light>)TwoLattes.createMarshaller(Light.class);
Light light= new Light();
Json.Object o = m.marshall(light);
System.out.println(o.toString());
}
}
Output:
--------
Exception in thread "main" java.lang.NullPointerException
at
com.twolattes.json.AbstractFieldDescriptor.marshall(AbstractFieldDescriptor.java
:46)
at
com.twolattes.json.ConcreteEntityDescriptor.marshallFields(ConcreteEntityDescrip
tor.java:137)
at
com.twolattes.json.ConcreteEntityDescriptor.marshall(ConcreteEntityDescriptor.ja
va:127)
at
com.twolattes.json.ConcreteEntityDescriptor.marshall(ConcreteEntityDescriptor.ja
va:18)
at com.twolattes.json.MarshallerImpl.marshall(MarshallerImpl.java:38)
at com.twolattes.json.MarshallerImpl.marshall(MarshallerImpl.java:34)
at Marsh.main(Marsh.java:26)
Original issue reported on code.google.com by [email protected]
on 4 Jun 2009 at 6:07
This:
@com.twolattes.json.Entity
static public class Foo {
@Value(name="bar") int foo;
@Value int getFoo() { return foo; }
}
@Test
public void testMarshaller() {
Foo foo = new Foo();
foo.foo = 42;
JSONObject o = Marshaller.create(Foo.class).marshall(foo);
}
will throw:
java.lang.IllegalArgumentException: Value with name foo is described
multiple times.
Original issue reported on code.google.com by [email protected]
on 8 Aug 2008 at 4:45
If we have the method
{{{
int size() { ...
}}}
we would like to annotate it with {{{@Value}}} instead of creating a getter
just for the library.
Original issue reported on code.google.com by [email protected]
on 28 Feb 2008 at 9:48
Remove the static function to register types and instead extend the create
signature to
create(Class c, Type... types);
This is much cleaner than horrible global mutable state which makes this
feature of the library untestable.
Original issue reported on code.google.com by [email protected]
on 1 Mar 2008 at 10:35
It would be great if the JsonMarshaller could support values of type
Class<?>
out of the box. For instance
@Entity
class MyEntity {
@Value Class<?> kind;
}
could marshall and unmarshall without any specific support.
Pros:
- nice out-of-the-box feature
Cons:
- requires something such as Class.forName when unmarshalling which for complex
applications may yield incorrect class if complex class loaders are needed
Original issue reported on code.google.com by [email protected]
on 20 Sep 2010 at 9:23
The entity
{{{
class A {
@Value int getWhatever() { ...
}
}}}
should not be required to have a no-arg constructor as it will never be
constructed.
Original issue reported on code.google.com by [email protected]
on 28 Feb 2008 at 11:05
Having types named String and Object leads to confusion. Attached is a
screen shot example of code completion in Eclipse. In this case it is not
possible to know if the methods await java.lang.String or Json.String.
I think that class names like JsonString or JsonObject for instance would
be far more clear.
Original issue reported on code.google.com by [email protected]
on 29 Apr 2010 at 11:14
Attachments:
Currently, the @Entity annotation has multiple four options (inline,
subclasses, discriminatorName and discriminator) which must be used in a
very specific and mutually exclusive way.
The inline annotation specifies that an entity must always be inlined, the
discriminatorName and subclasses options must be used together to specify
that an entity is the root of a polymorphic hierarchy and the discriminator
option specifies a leaf of a polymorphic hierarchy.
In fact, these represents ways to marshall an entity or a marshalling
strategy.
I propose to deprecate all these options and create instead a
MarshallingStrategy strategy();
option where MarshallingStrategy is an abstract annotation with three
concrete subclasses
@Inline
@PolymorphicRoot(subclasses = ..., discriminatorName = ...)
@PolymorphicLeaf(discriminator = ...)
which would define how to marshall a specific entity.
Following the "do the work at compile time" mindset, the library would be
refactored to have entity descriptors for each strategy.
After this refactoring, we could make the
@Value(inline = true) EntityClassHere e;
be compiled into the same kind of descriptor as if EntityClassHere were
annotated with the @Inline strategy. This would speed up the marshalling by
avoiding unecesseray "if is inlined then/else" checks everywhere.
Original issue reported on code.google.com by [email protected]
on 3 Jan 2009 at 2:13
class NonEntity { }
@Entity
class A {
@Value List<NonEntity> foo;
}
In this situation I'd like to say @Value(type = NonEntityType.class) to
specify the user-defined type of the colleciton element type.
Original issue reported on code.google.com by [email protected]
on 6 Jan 2010 at 7:43
Options page, "views" section:
"Views allow you to specify different waays to marshall entities."
Original issue reported on code.google.com by [email protected]
on 10 Jun 2010 at 11:43
When an unexpected leaf node is unmarshalled, the JM has an NPE instead of
explaining the problem to the user.
@Entity(discrinimatorName = "type", subclasses = {})
static class Person {
}
@Entity(discriminator = "person")
static class Employee extends Persion {
}
If you look at
http://code.google.com/p/jsonmarshaller/source/browse/trunk/src/com/twolattes/js
on/PolymorphicEntityDescriptor.java?r=81
The check is done at line 85, but not when the inline code is used.
Original issue reported on code.google.com by [email protected]
on 21 Apr 2009 at 8:05
Entity:
JSON:
toString()
[junit]
{"footer":"footer","header":null,"displayType":"display","imageText":null}
toString(2)
[junit] ------------- Standard Output ---------------
[junit] {
[junit] "footer": "footer",
[junit] "header": {},
[junit] "displayType": "display",
[junit] "imageText": {},
[junit] }
What is the expected output? What do you see instead?
First one works
Second one fails with:
[junit] org.json.JSONObject
[junit] java.lang.ClassCastException: org.json.JSONObject
[junit] at
com.twolattes.json.StringDescriptor.unmarshall(StringDescriptor.java:30)
[junit] at
com.twolattes.json.StringDescriptor.unmarshall(StringDescriptor.java:12)
[junit] at
com.twolattes.json.ConcreteEntityDescriptor.unmarshallFields(ConcreteEntity
Descriptor.java:273)
[junit] at
com.twolattes.json.ConcreteEntityDescriptor.unmarshall(ConcreteEntityDescri
ptor.java:231)
[junit] at
com.twolattes.json.Marshaller.unmarshall(Marshaller.java:183)
[junit] at
com.twolattes.json.Marshaller.unmarshall(Marshaller.java:172)
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 30 Sep 2008 at 8:07
class FormulaRanking {
class JsonType extends JsonTypeAdapter<FormulaRanking> {
JsonType() { ... }
}
}
What is the expected output? What do you see instead?
Expected: some error indicating that JsonType is a non-static inner class.
Actual: "class ... is missing a no-argument constructor"
I initially thought this was related to access modifiers and tried a few
variations of package / public / private before noticing that it wasn't a
static class. The reported error is technically correct, but misleading.
Original issue reported on code.google.com by [email protected]
on 27 Jul 2010 at 10:04
@Entity
class A {
String a;
@Value(name = "foo")
String getA() { ...
@Value(name = "foo")
void setAWithWeirdName(String a) { ...
}
Original issue reported on code.google.com by [email protected]
on 6 Apr 2008 at 10:10
It would be great if the jsonmarshaller provided some form of support for
unmarshalling streams.
This is one way I could see this working:
For the input:
[
{"type": "foo", "fooValue": 1},
//pause
{"type": "bar", "barValue": "abc"},
//pause
{"type": "baz", "bazValue": false}
]
Code along these lines would provide streaming unmarshalling:
InputStream is = //...;
TwoLattes.createMarshaller(FooBarBaz.class).streamingUnmarshallList(is,
new EntityCallback<FooBarBaz>() {
void callback(FooBarBaz entity) {
//yields individual instances of FooBarBaz from the provided input stream
}
});
Original issue reported on code.google.com by [email protected]
on 21 Apr 2010 at 9:44
@Value(type = MyType.class) is fine for MyObject myObj
but if I have for instance
List<MyObject> myObjects
I can't annotate them to reuse MyType.class and need a new converter able
to handle a List<MyObject>. The library should provide direct support for that.
Btw: doc is outdated
http://code.google.com/p/jsonmarshaller/wiki/UserDefinedTypes
Original issue reported on code.google.com by [email protected]
on 6 May 2010 at 4:01
When using jsonmarshaller in a non-signed applet it'll throw
AccessControlExceptions
Up till version 0.20 those could be avoided by setting fields with an @Value
annotation to public, but in 0.21 that also no longer works (resulting
exception below).
The checks done at DescriptorFactory.java:116 seem to me to be some sanity
checks for @Value annotations on parent classes. If those checks result in a
AccessControlException, then any annotations there are unreachable any way, so
it should be safe to continue. Am I right in that assumption?
Hylke
Using public accessors now results in:
java.security.AccessControlException: access denied
(java.lang.RuntimePermission accessDeclaredMembers)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkMemberAccess(SecurityManager.java:1662)
at java.lang.Class.checkMemberAccess(Class.java:2157)
at java.lang.Class.getDeclaredFields(Class.java:1742)
at com.twolattes.json.DescriptorFactory.createConcreteEntityDescriptor(DescriptorFactory.java:116)
at com.twolattes.json.DescriptorFactory.create(DescriptorFactory.java:97)
at com.twolattes.json.EntityMarshallerImpl.<init>(EntityMarshallerImpl.java:27)
at com.twolattes.json.TwoLattes$Builder.createEntityMarshaller(TwoLattes.java:215)
at com.twolattes.json.TwoLattes$Builder.createMarshaller(TwoLattes.java:211)
at com.twolattes.json.TwoLattes.createMarshaller(TwoLattes.java:154)
Original issue reported on code.google.com by [email protected]
on 13 Nov 2010 at 7:25
See code below. Currently the behavior of the JsonMarshaller is somewhat
surprising. It would be a better to throw with a clear message.
@Test
public void subclass() {
assertEquals("{}", TwoLattes.createMarshaller(Foo.class).marshall(new Foo()).toString());
}
@Entity static class Foo extends Bar {}
static class Bar {
@Value String foo = "bar";
}
Original issue reported on code.google.com by [email protected]
on 10 Jul 2010 at 8:13
seems that enum types are not supported
@Entity
public enum BuildTags { TEST,STABLE }
JSON:
"typology":{"id":1}
get exception during unmarshall
java.lang.IllegalStateException: java.lang.InstantiationException:
com.finantix.builder.BuildTags
Original issue reported on code.google.com by [email protected]
on 15 Oct 2008 at 9:58
Having a public (instead of private) default constructor lead to this exception:
java.lang.IllegalStateException: kava.lang.IllegalAccessException: Class
com.twolattes.json.ConcreteEntityDescriptor can not access a member of class
com.kaching.XXX with modifiers "public" at
com.twolattes.json.ConcreteEntityDescriptor.unmarshall(ConcreteEntityDescriptor.
java:170) ...
Original issue reported on code.google.com by [email protected]
on 6 Jul 2010 at 4:14
If a class A extends a class B and B is annotated as
{{{
@Entity(subclasses = A.class, discriminatorName = ...)
class B { ...
}}}
it should not need a no arg constructor since it will never be constructed
by the library.
Original issue reported on code.google.com by [email protected]
on 24 Feb 2008 at 4:54
The entity
@Entity
class Foo {
@Value
SortedSet<Bar> bar;
}
cannot be unmarshalled as the library assigns HashSet.
Original issue reported on code.google.com by [email protected]
on 4 Mar 2008 at 3:52
The following Json#fromString call
assertEquals(Json.string("foo"), Json.fromString("foo"));
throws the exception
java.lang.IllegalArgumentException: false expected
The string "false" is indeed ambiguous, it could either be Json.FALSE or
Json.string("false"). However, all other strings starting with an "f" aren't
ambiguous.
I am not sure what the expected output should be. I ran into this issue when
using a Marshaller<String>
createMarshaller(String.class).unmarshall(Json.fromString("foo"));
Original issue reported on code.google.com by [email protected]
on 13 Sep 2010 at 9:01
What steps will reproduce the problem?
public BigClass {
List<UiProperty<String>> props;
}
@Entity public Class UiProperty<T>{
T value;
}
What is the expected output?
What do you see instead?
java.lang.IllegalStateException
at
com.twolattes.json.EntitySignatureVisitor.visitTypeVariable(EntitySignatureVisit
or.java:192)
at org.objectweb.asm.signature.SignatureReader.a(Unknown Source)
at org.objectweb.asm.signature.SignatureReader.accept(Unknown Source)
at com.twolattes.json.DescriptorFactory.create(DescriptorFactory.java:135)
at com.twolattes.json.EntityFieldVisitor.visitEnd(EntityFieldVisitor.java:53)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at
com.twolattes.json.DescriptorFactory.createConcreteEntityDescriptor(DescriptorFa
ctory.java:100)
at com.twolattes.json.DescriptorFactory.create(DescriptorFactory.java:70)
at
com.twolattes.json.EntitySignatureVisitor.visitClassType(EntitySignatureVisitor.
java:79)
at org.objectweb.asm.signature.SignatureReader.a(Unknown Source)
at org.objectweb.asm.signature.SignatureReader.a(Unknown Source)
at org.objectweb.asm.signature.SignatureReader.accept(Unknown Source)
at com.twolattes.json.DescriptorFactory.create(DescriptorFactory.java:135)
at com.twolattes.json.EntityFieldVisitor.visitEnd(EntityFieldVisitor.java:53)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at
com.twolattes.json.DescriptorFactory.createConcreteEntityDescriptor(DescriptorFa
ctory.java:100)
at com.twolattes.json.DescriptorFactory.create(DescriptorFactory.java:70)
at
com.twolattes.json.EntitySignatureVisitor.visitClassType(EntitySignatureVisitor.
java:79)
at org.objectweb.asm.signature.SignatureReader.a(Unknown Source)
at org.objectweb.asm.signature.SignatureReader.a(Unknown Source)
at org.objectweb.asm.signature.SignatureReader.accept(Unknown Source)
at com.twolattes.json.DescriptorFactory.create(DescriptorFactory.java:135)
at com.twolattes.json.EntityFieldVisitor.visitEnd(EntityFieldVisitor.java:53)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at
com.twolattes.json.DescriptorFactory.createConcreteEntityDescriptor(DescriptorFa
ctory.java:100)
at com.twolattes.json.DescriptorFactory.create(DescriptorFactory.java:70)
at com.twolattes.json.Marshaller.<init>(Marshaller.java:41)
at com.twolattes.json.Marshaller.create(Marshaller.java:62)
at
com.poweredbyrex.dashboard.builder.JsonBuilder.toJsonString(JsonBuilder.java:87)
at
com.poweredbyrex.dashboard.builder.JsonBuilderTest.testToJsonStringDashboard(Jso
nBuilderTest.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at ...
What version of the product are you using? On what operating system?
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 4 Apr 2008 at 1:01
What steps will reproduce the problem?
1. Marshall any Collection (java.util.ArrayList, etc.) or Map
(java.util.HashMap)
What is the expected output? What do you see instead?
[{"a":"b"}, {"c":"d"}, [], ....]
What version of the product are you using? On what operating system?
0.10
Original issue reported on code.google.com by [email protected]
on 29 Feb 2008 at 1:20
What steps will reproduce the problem?
1. Entity Class :
@Entity
public class EntityMap {
@Value
private final Map<Email, String> emails = new HashMap<Email, String>();
public void addEmail(String name, Email email) {
emails.put(email, name);
}
public int numberOfEmails() {
return emails.size();
}
public String get(String name) {
return "";//emails.get(name);
}
public Map<Email, String> getEmails() {
return emails;
}
}
What is the expected output? What do you see instead?
Please use labels and text to provide additional information.
Exception:
java.lang.IllegalArgumentException: Map<String, ...> must be used.
Signature Ljava/util/Map<Lcom/twolattes/json/Email;Ljava/lang/String;>;
at com.twolattes.json.EntitySignatureVisitor.getDescriptor
(EntitySignatureVisitor.java:205)
at com.twolattes.json.DescriptorFactory.create
(DescriptorFactory.java:162)
at com.twolattes.json.EntityFieldVisitor.visitEnd
(EntityFieldVisitor.java:72)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at
com.twolattes.json.DescriptorFactory.createConcreteEntityDescriptor
(DescriptorFactory.java:117)
at com.twolattes.json.DescriptorFactory.create
(DescriptorFactory.java:82)
at com.twolattes.json.DescriptorFactoryTest.create
(DescriptorFactoryTest.java:231)
at com.twolattes.json.DescriptorFactoryTest.testMap
(DescriptorFactoryTest.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody
(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected
(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod
(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run
(TestMethodRunner.java:45)
at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod
(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run
(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected
(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run
(TestClassRunner.java:52)
at org.junit.internal.runners.CompositeRunner.run
(CompositeRunner.java:29)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected
(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run
(TestClassRunner.java:52)
at com.intellij.rt.junit4.Junit4ClassSuite.run
(Junit4ClassSuite.java:99)
at com.intellij.rt.execution.junit.JUnitStarter.main
(JUnitStarter.java:40)
Note:
In EntitySignatureVisitor.java, it is hardcoded that all the keys in a map
must be of type String.
It should allow a key of any type, as in this case it of type email which
is a valid key.
If there is a restriction that you can not provide this functionality,
than you can remove this check and use toString() of the object to get the
string represenation of the String.
Original issue reported on code.google.com by [email protected]
on 18 Jan 2010 at 9:53
@Entity
public class Data {
@Value int[] rows;
public void set(int[] _rows){..}
public int[] get() {..}
}
This throws IllegalArgumentException when setting the field. I believe this
is because and Integer[] is created and attempted to set the field.
The stack-trace is below. I working on a patch since I need this feature soon.
java.lang.IllegalArgumentException
at
sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java
:63)
at java.lang.reflect.Field.set(Field.java:656)
at
com.twolattes.json.FieldDescriptor$DirectAccessFieldDescriptor.setFieldValue(Fie
ldDescriptor.java:168)
at
com.twolattes.json.ConcreteEntityDescriptor.unmarshallFields(ConcreteEntityDescr
iptor.java:271)
at
com.twolattes.json.ConcreteEntityDescriptor.unmarshall(ConcreteEntityDescriptor.
java:229)
at com.twolattes.json.Marshaller.unmarshall(Marshaller.java:183)
at com.twolattes.json.Marshaller.unmarshall(Marshaller.java:172)
at
...............................JsonBuilderTest.testJson(JsonBuilderTest.java:196
)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Original issue reported on code.google.com by [email protected]
on 11 Apr 2008 at 2:28
JSon.Value.toString should give a String representation of the JSON object.
In fact it is already the case and JSon.BaseValue.toString does the job
right, but this should be documented in the interface JSon.Value to be sure
that users can rely on toString.
Original issue reported on code.google.com by [email protected]
on 28 Apr 2010 at 1:09
Entity:
@Entity
public class Complex {
@Value(type = com.twolattes.json.types.URLType.class)
public List<URL> urlList;
public static void main(String args[]) {
try{
Complex c = new Complex();
c.urlList = new ArrayList<URL>();
c.urlList.add(new URL("http","www.google.com",8080,""));
c.urlList.add(new URL("http","www.yahoo.com",8080,""));
Marshaller<Complex> m = TwoLattes.createMarshaller(Complex.class);
Json.Object obj = m.marshall(c);
System.out.println(obj);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
JSON:
What is the expected output? What do you see instead?
expected output:
{"urlList":["http://www.google.com:8080","http://www.yahoo.com:8080"]}
I see null, and the exception is mentioned below.
Please provide any additional information below.
I am having the following exception right now:
java.lang.ClassCastException
Original issue reported on code.google.com by [email protected]
on 24 Dec 2009 at 5:11
This might be more of a feature request than of a bug report:
Assume you have the attached files. Note this: public User c = a;
You might expect it to marshall and unmarshall correctly so that c and a
are the same.
Expected output:
test.User@7919298d
test.User@62f72617
test.User@7919298d
{"a":{"name":"MyName","x":-1},"b":{"name":"MyName","x":-1},"c":{"name":"MyName",
"x":-1}}
test.User@33dff3a2
test.User@33f42b49
test.User@33dff3a2
Actual output:
test.User@7919298d
test.User@62f72617
test.User@7919298d
{"a":{"name":"MyName","x":-1},"b":{"name":"MyName","x":-1},"c":{"name":"MyName",
"x":-1}}
test.User@33dff3a2
test.User@33f42b49
test.User@6345e044
(Look at the last line of the examples)
It's quite obvious that it isn't unmarshalling so a and c are the same.
Suggestion to fix this:
Add some extra fields to use as metadata and put the actual object in an
other field named "data". References can be a type of metadata. Later when
unmarshalling it will detect the reference metadata and create the correct
reference.
Original issue reported on code.google.com by [email protected]
on 26 May 2010 at 8:27
Attachments:
It would be useful to be able to specify the scale and the rounding mode on
numerical types. For instance
@Value(scale = 2) double price;
or
@Value(scale = 10, roundingMode = RoundingMode.FLOOR) BigDecimal percent;
By default, the number's scale would be preserved (current behavior) and
the default rounding mode would be the banker's rounding
(RoundingMode.HALF_EVEN).
When marshalled, the scale would be reduced to the specified scale. The
scale would never be extended. Therefore if price = 5, it would marshall as
"price":5
but if price is 5.064 it would marshall as
"price":5.06
When unmarshalled, the value would be rounded if needed to the specified
scale using the rounding mode specified.
Original issue reported on code.google.com by [email protected]
on 18 Dec 2008 at 1:27
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.