AutoBean with Subclasses
Hi, I have 4 interfaces: public interface Ainterface{ getName()/setName(); getShape()/setShape(); } public interface Binterface extends Ainterface{ getWidth()/setWidth(); getHeight()/setHeight(); ... } public interface Cinterface extends Ainterface{ getRadius()/setRadius(); ... } public interface Dinterface { Ainterface getA(); void setA(Ainterface a); ... } I have included all interfaces in my AutoBeanFactory. Question: when I decode/encode Dinterface, how do I know if Ainterface is extended by Binterface or Cinterface? How does AutoBean support polymorphism? To make it easier, I can add a variable (for ex, shape) in Ainterface to indicate which Binterface or Cinterface I have and then cast Ainterface to Binterface/Cinterface. However, I run into ClassCastException. Should I have separate interfaces; one that consists Binterface and one consists Cinterface? Is there other solution to this problem? Thank you, -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/WwTERx0IZRsJ. To post to this group, send email to google-web-toolkit@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
JSONParser.parseStrict() with \"
Hi, I have JSON string that contains \". When I pass this to either parseStrict() or parseLenient(), I get back string with " instead of \". I tested this with JS eval() as well. eval() returns string with \". Anyone know how to work around this? Thank you. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscr...@googlegroups.com. To post to this group, send email to google-web-toolkit@googlegroups.com. Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: JSONParser.parseStrict() with \"
Before calling parseStrict(): {"name":"item_name","index":0,*"text":"Kindle Fire HD 8.9\"..."*} After parseStrict(): {"name":"item_name", "index":0, *"text":"Kindle Fire HD 8.9" ..."*} On Sunday, March 24, 2013 3:14:50 AM UTC-7, Thomas Broyer wrote: > > Could you show your code? (JSON string I mean) > > On Sunday, March 24, 2013 9:14:18 AM UTC+1, rkulisas wrote: >> >> Hi, >> >> I have JSON string that contains \". When I pass this to either >> parseStrict() or parseLenient(), I get back string with " instead of \". I >> tested this with JS eval() as well. eval() returns string with \". Anyone >> know how to work around this? >> >> Thank you. >> > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscr...@googlegroups.com. To post to this group, send email to google-web-toolkit@googlegroups.com. Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: JSONParser.parseStrict() with \"
//josn is {"name":"item_name","index":0,*"text":"Kindle Fire HD 8.9\"..."*} JSONValue value = JSONParser.parseStrict(json); JSONObject obj; JSONString name, text; JSONNumber nxd; if ((obj = value.isObject()) == null ) return null; if ((value = obj.get("name")) != null) if ((name = value.isString()) != null) field.setName(name.stringValue()); if ((value = obj.get("text")) != null) if ((text = value.isString()) != null){ System.out.println("VALUE:" + value.toString()); //VALUE:"Kindle Fire HD 8.9\" ..." System.out.println("TEXT:" + text.stringValue()); //TEXT:Kindle Fire HD 8.9" ... field.setText(text.stringValue()); } Am I supposed to use JSONValue.toString() to get my string value instead? Why JSONString.stringValue() doesn't parse properly? Thank you On Monday, March 25, 2013 2:04:45 AM UTC-7, Thomas Broyer wrote: > > > > On Monday, March 25, 2013 3:13:53 AM UTC+1, rkulisas wrote: >> >> Before calling parseStrict(): >> {"name":"item_name","index":0,*"text":"Kindle Fire HD 8.9\"..."*} >> > > So the "text" property of the object is the string « Kindle Fire HD > 8.9"... » > > >> After parseStrict(): >> {"name":"item_name", "index":0, *"text":"Kindle Fire HD 8.9" ..."*} >> > > JsonUtils gives you an object, not a JSON string, so the above line > doesn't mean much things. > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscr...@googlegroups.com. To post to this group, send email to google-web-toolkit@googlegroups.com. Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: JSONParser.parseStrict() with \"
Hi Thomas, I don't have control over the string value that gets passed in to me. If I don't get \" in return, the JSON will be invalid. I'm having similar problem to this thread. http://stackoverflow.com/questions/13420115/padding-quotes-in-jsonobject Thank you On Monday, March 25, 2013 3:57:19 AM UTC-7, Thomas Broyer wrote: > > > > On Monday, March 25, 2013 11:23:51 AM UTC+1, rkulisas wrote: >> >> //josn is {"name":"item_name","index":0,*"text":"Kindle Fire HD 8.9\"..." >> *} >> >> JSONValue value = JSONParser.parseStrict(json); >> >> JSONObject obj; >> >> JSONString name, text; >> >> JSONNumber nxd; >> >> if ((obj = value.isObject()) == null ) return null; >> >> if ((value = obj.get("name")) != null) >> >> if ((name = value.isString()) != null) >> >>field.setName(name.stringValue()); >> >> if ((value = obj.get("text")) != null) >> >> if ((text = value.isString()) != null){ >> >> System.out.println("VALUE:" + value.toString()); //VALUE:"Kindle Fire >> HD 8.9\" ..." >> >> System.out.println("TEXT:" + text.stringValue()); //TEXT:Kindle Fire HD >> 8.9" ... >> >> field.setText(text.stringValue()); >> >> } >> Am I supposed to use JSONValue.toString() to get my string value >> instead? Why JSONString.stringValue() doesn't parse properly? >> > > The question is more: why do you want the \ to be there? > It's in your JSON because JSON uses " to markup string literals and thus > has to escape " that appears within the string value, just like you do in > Java or JavaScript or so many other languages (C, etc.) > > stringValue() *does* return the correct value, it's just that you're > expecting something else. > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscr...@googlegroups.com. To post to this group, send email to google-web-toolkit@googlegroups.com. Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: JSONParser.parseStrict() with \"
For my case, I want to keep \". So I'd need to do replaceAll("\"","\\\"") on all my java object toString() when I want to convert this back to JSON format. Is there a better GWT library to do this conversion? This is now I convert back to JSON string: public String toString(){ return "{" + "\"name\":" + ((name == null)? "null" : ("\"" + name + "\"")) + ", \"index\":" + index + ", \"text\":" + ((text == null)? "null" : ("\"" + text + "\"")) + "}"; } On Monday, March 25, 2013 1:23:43 PM UTC-7, rkulisas wrote: > > Hi Thomas, > > I don't have control over the string value that gets passed in to me. If I > don't get \" in return, the JSON will be invalid. I'm having similar > problem to this thread. > http://stackoverflow.com/questions/13420115/padding-quotes-in-jsonobject > > Thank you > > On Monday, March 25, 2013 3:57:19 AM UTC-7, Thomas Broyer wrote: >> >> >> >> On Monday, March 25, 2013 11:23:51 AM UTC+1, rkulisas wrote: >>> >>> //josn is {"name":"item_name","index":0,*"text":"Kindle Fire HD >>> 8.9\"..."*} >>> >>> JSONValue value = JSONParser.parseStrict(json); >>> >>> JSONObject obj; >>> >>> JSONString name, text; >>> >>> JSONNumber nxd; >>> >>> if ((obj = value.isObject()) == null ) return null; >>> >>> if ((value = obj.get("name")) != null) >>> >>> if ((name = value.isString()) != null) >>> >>>field.setName(name.stringValue()); >>> >>> if ((value = obj.get("text")) != null) >>> >>> if ((text = value.isString()) != null){ >>> >>> System.out.println("VALUE:" + value.toString()); //VALUE:"Kindle Fire >>> HD 8.9\" ..." >>> >>> System.out.println("TEXT:" + text.stringValue()); //TEXT:Kindle Fire >>> HD 8.9" ... >>> >>> field.setText(text.stringValue()); >>> >>> } >>> Am I supposed to use JSONValue.toString() to get my string value >>> instead? Why JSONString.stringValue() doesn't parse properly? >>> >> >> The question is more: why do you want the \ to be there? >> It's in your JSON because JSON uses " to markup string literals and thus >> has to escape " that appears within the string value, just like you do in >> Java or JavaScript or so many other languages (C, etc.) >> >> stringValue() *does* return the correct value, it's just that you're >> expecting something else. >> > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscr...@googlegroups.com. To post to this group, send email to google-web-toolkit@googlegroups.com. Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en. For more options, visit https://groups.google.com/groups/opt_out.