Received: by 10.236.187.7 with SMTP id x7mr26911842yhm.7.1322926799782; Sat, 03 Dec 2011 07:39:59 -0800 (PST) X-BeenThere: json-io@googlegroups.com Received: by 10.101.144.35 with SMTP id w35ls1058409ann.1.gmail; Sat, 03 Dec 2011 07:39:59 -0800 (PST) Received: by 10.101.29.30 with SMTP id g30mr4839941anj.33.1322926799512; Sat, 03 Dec 2011 07:39:59 -0800 (PST) Received: by 10.101.29.30 with SMTP id g30mr4839940anj.33.1322926799489; Sat, 03 Dec 2011 07:39:59 -0800 (PST) Return-Path: Received: from mail-gx0-f172.google.com (mail-gx0-f172.google.com [209.85.161.172]) by gmr-mx.google.com with ESMTPS id m17si2516440ybe.0.2011.12.03.07.39.59 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 03 Dec 2011 07:39:59 -0800 (PST) Received-SPF: pass (google.com: domain of jde...@gmail.com designates 209.85.161.172 as permitted sender) client-ip=209.85.161.172; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jde...@gmail.com designates 209.85.161.172 as permitted sender) smtp.mail=jde...@gmail.com; dkim=pass (test mode) header...@gmail.com Received: by ggnk5 with SMTP id k5so313462ggn.3 for ; Sat, 03 Dec 2011 07:39:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=FVhp4053mu76xaDhO3glbzawNRk58RiBgvxsoeXj2zA=; b=lMkov7BzroX0GUO9r0aIBVrXnM1WkhK6cECxbfcfq9Xx6a6PNEweEwP5R9ZXKZy2zd HFN9wqegSGtPblwVkc/shSb7meRyX2lrraebLkRAOi1HUqZkFG/qWwjGBlu9+yT8Cje0 iv3KiNmPSOrNN/GMGOZusbU+iU0cdGL8m5COI= MIME-Version: 1.0 Received: by 10.101.213.24 with SMTP id p24mr529568anq.154.1322926799302; Sat, 03 Dec 2011 07:39:59 -0800 (PST) Received: by 10.150.201.15 with HTTP; Sat, 3 Dec 2011 07:39:59 -0800 (PST) In-Reply-To: References: <7d471892-5add-44bd-85f2-2916980e11bc@o1g2000vbe.googlegroups.com> Date: Sat, 3 Dec 2011 10:39:59 -0500 Message-ID: Subject: Re: Android problem From: John DeRegnaucourt To: json-io@googlegroups.com Content-Type: multipart/alternative; boundary=001636d33a61efb20204b331e533 --001636d33a61efb20204b331e533 Content-Type: text/plain; charset=ISO-8859-1 Sure, I will see if I can bang that out this weekend. On Sat, Dec 3, 2011 at 10:36 AM, Ron wrote: > Will you be making the changes soon for the no-arg check? > > > On Fri, Dec 2, 2011 at 5:31 PM, John DeRegnaucourt wrote: > >> Ron, >> >> I like the check-first for no-arg constructor, then use Constructor loop. >> That should work (until I can implement the generic non-constructor >> calling 'new' operation.) >> >> John >> >> >> On Fri, Dec 2, 2011 at 5:05 PM, Ron wrote: >> >>> John, >>> >>> The Java object I am serializing/deserializing is a simple class with >>> mostly primitive elements (String, boolean, int) and ArrayList/HashMap >>> components that also have String elements in them. The error messages >>> showed it was trying to instantiate a "java.util.HashMap$HashMapEntry" >>> class. I've reviewed my code to see if one of the Collection objects is >>> storing a HashMapEntry object instead of an intended String, but I could >>> not locate it (but doesn't mean it isn't... just that I didn't see it). >>> >>> There are no system.out statements for the error... I suspect Android's >>> Dalvik VM is pushing those to the console because the newInstance method is >>> trying to instantiate a no-arg constructor for a HashMapEntry and there is >>> none in Android. I am not sure what to do either because this is starting >>> to get way beyond my expertise. >>> >>> I'll keep looking at my code, but I wonder if your code could first >>> validate there is a no-arg constructor using reflection before attempting >>> to create the class... that seems to be the safest all around... or just do >>> the no-arg constructor last like my solution. Let me know if you'd like me >>> to test any new code for you. >>> >>> -Ron >>> >>> >>> On Fri, Dec 2, 2011 at 1:29 PM, John DeRegnaucourt wrote: >>> >>>> Ron, >>>> >>>> I am impressed with how quickly you fixed the issue for your situation. >>>> The question I have, though, what exactly makes this work? Once I >>>> understand that, then I think we could use your solution in the main >>>> library code. >>>> >>>> I am thinking that one of the classes your are attempting to >>>> instantiate has an very odd public constructor that is emitting this output >>>> when it is attempted to be created, as it the class designer wanted a more >>>> specific constructor called. If we put in the fix you have, it will get >>>> around the class you have run into, however, there could just as well be a >>>> class where if you use a non-public constructor, it could emit this type of >>>> error message, but then not emit it if the public constructor is used. >>>> >>>> I would really like to know how this "no ()" message is getting >>>> written out. Is it via a System.out (god forbid)? If so, we could >>>> temporarily re-direct stdout, do the instantiation, and then put back the >>>> System.out mapping. >>>> >>>> The fix I am suggesting, would hide System.out.println() output while >>>> the object is instantied, and then restore the ability for that stream to >>>> be used. We'd have to think through the threading ramifications of such a >>>> fix. >>>> >>>> Another thought is if I can instantiate all classes using some >>>> 'trickery' that by passes all constructor executions, and just gets the >>>> object space created, similar to a "malloc()" call from the C world. In >>>> normal coding, this would be a bad thing as you want the constructor >>>> executed. In the serialization case, however, all we are trying to do is >>>> recreate the exact same object state as it existed on the other end. I >>>> will also looking a generic / generalized object instantiator that can be >>>> used for all objects. That is what is truly desired here. >>>> >>>> Thoughts, comments? >>>> >>>> Regards, >>>> John >>>> >>>> >>>> On Wed, Nov 30, 2011 at 7:28 PM, Ron wrote: >>>> >>>>> John,, >>>>> >>>>> It fails when instantiating class "java.util.HashMap$HashMapEntry". >>>>> All the other elements in the object I am trying to reconstruct work fine, >>>>> only the HashMap$HashMapEntry causes a problem. Which is odd because >>>>> instantiating HashMaps classes didn't throw an error. >>>>> >>>>> I reworked the 'newInstance(Class c)' method to attempt the no-arg >>>>> constructor after checking for the other constructors first. This worked >>>>> and the messages went away. I attached the fix. Let me know if you want >>>>> me to do other testing. >>>>> >>>>> -Ron >>>>> >>>>> >>>>> On Wed, Nov 30, 2011 at 2:22 PM, John wrote: >>>>> >>>>>> I assume these are happening during the 'reading' side of >>>>>> serialization (not the 'writing' side). If so, I suggest adding some >>>>>> 'println debugging' to the 'newInstance(Class c)' method in >>>>>> JsonReader.java to see what class's are causing this to happen. >>>>>> >>>>>> When the JsonReader begins instantiating classes to reconstruct the >>>>>> object graph on the destination side, it first attempts to use a >>>>>> public constructor. If that fails to instantiate, it then goes >>>>>> through the rest of the constructors (public or private) until one of >>>>>> them gets the instance instantiated. Once instantiated, it then >>>>>> copies the appropriate values to the appropriate fields. >>>>>> >>>>>> There is a chance that one of the objects you are attempting to >>>>>> instantiate print's out this message while it is going through this >>>>>> process. I would locate which object is doing this, and see if that >>>>>> behavior can be turned off. >>>>>> >>>>>> I am interested in hearing about what you find. >>>>>> >>>>>> - John >>>>>> >>>>>> On Nov 30, 3:15 pm, Rmac wrote: >>>>>> > Hi, >>>>>> > >>>>>> > When I use json-io in my Android app I get lots of "newInstance >>>>>> > failed: no ()" messages on the Java console. It appears the >>>>>> > serialization/deserialization works properly, but the messages are a >>>>>> > concern. What could be the cause and resolution? Thanks. >>>>>> > >>>>>> > -Ron >>>>>> >>>>> >>>>> >>>> >>> >> > --001636d33a61efb20204b331e533 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sure, I will see if I can bang that out this weekend.=A0

On Sat, Dec 3, 2011 at 10:36 AM, Ron <rony...@gmail.com>= wrote:
Will you be making the changes soon for the= no-arg check?


On Fri, Dec 2, 2011 at 5:31 PM, John DeRegnaucourt <jde...@gmail.com>= ; wrote:
Ron,

I like the check-fir= st for no-arg constructor, then use Constructor loop. =A0That should work (= until I can implement the generic non-constructor calling 'new' ope= ration.)

John


On Fri, Dec = 2, 2011 at 5:05 PM, Ron <rony...@gmail.com> wrote:
John,

The Java object I am serializing/deserializing is = a simple class with mostly primitive elements (String, boolean, int) and Ar= rayList/HashMap components that also have String elements in them. =A0The e= rror messages showed it was trying to instantiate a=A0"java.util.HashM= ap$HashMapEntry" class. =A0I've reviewed my code to see if one of = the Collection objects is storing a HashMapEntry object instead of an inten= ded String, but I could not locate it (but doesn't mean it isn't...= just that I didn't see it).

There are no system.out statements for the error... I s= uspect Android's Dalvik VM is pushing those to the console because the = newInstance method is trying to instantiate a no-arg constructor for a Hash= MapEntry and there is none in Android. =A0I am not sure what to do either b= ecause this is starting to get way beyond my expertise.

I'll keep looking at my code, but I wonder if your = code could first validate there is a no-arg constructor using reflection be= fore attempting to create the class... that seems to be the safest all arou= nd... or just do the no-arg constructor last like my solution. =A0Let me kn= ow if you'd like me to test any new code for you.

-Ron


On Fri, Dec 2, 2011 at 1:29 PM, John DeRegnaucourt <jdereg= @gmail.com> wrote:
Ron,

I am impressed with how quickly you fixed the issue= for your situation. =A0The question I have, though, what exactly makes thi= s work? =A0Once I understand that, then I think we could use your solution = in the main library code. =A0

I am thinking that one of the classes your are attempti= ng to instantiate has an very odd public constructor that is emitting this = output when it is attempted to be created, as it the class designer wanted = a more specific constructor called. =A0If we put in the fix you have, it wi= ll get around the class you have run into, however, there could just as wel= l be a class where if you use a non-public constructor, it could emit this = type of error message, but then not emit it if the public constructor is us= ed.

I would really like to know how this "no <init&= gt;()" message is getting written out. =A0Is it via a System.out (god = forbid)? =A0If so, we could temporarily re-direct stdout, do the instantiat= ion, and then put back the System.out mapping.=A0

The fix I am suggesting, would hide System.out.println(= ) output while the object is instantied, and then restore the ability for t= hat stream to be used. =A0We'd have to think through the threading rami= fications of such a fix.

Another thought is if I can instantiate all classes usi= ng some 'trickery' that by passes all constructor executions, and j= ust gets the object space created, similar to a "malloc()" call f= rom the C world. =A0In normal coding, this would be a bad thing as you want= the constructor executed. =A0In the serialization case, however, all we ar= e trying to do is recreate the exact same object state as it existed on the= other end. =A0I will also looking a generic / generalized object instantia= tor that can be used for all objects. =A0That is what is truly desired here= .

Thoughts, comments?

Regards,
John


On Wed, Nov 30, 2011 at 7:28 PM, Ron <rony...@gmail.com> wro= te:
John,,

It fails when inst= antiating class "java.util.HashMap$HashMapEntry". =A0All the othe= r elements in the object I am trying to reconstruct work fine, only the=A0H= ashMap$HashMapEntry causes a problem. =A0Which is odd because instantiating= HashMaps classes didn't throw an error.

I reworked the 'newInstance(Class c)' method to= attempt the no-arg constructor after checking for the other constructors f= irst. =A0This worked and the messages went away. =A0I attached the fix. =A0= Let me know if you want me to do other testing.

-Ron








--001636d33a61efb20204b331e533--