I am developing a mobile application which serializes a class containing a couple of boolean properties.
It treats boolean properties as integers, hence serializes them as "0" or "1".
On server side (ASP.NET Web Service), JavascriptSerializer tries to convert "0" to boolean, and gives Error: "0 is not a valid value for Boolean"
I need to modify javascript serializer so that when it encounters a "0" or "1" and expects a boolean, it converts their corresponding value to bool.
I investigated JavascriptConverter abstract class but did not help. Could you support with such a working example?
Thanks in advance
Its better converting true to 1 after Serialization.
Use some wrapper class or custom code
Related
I am receiving xml from a webservice call that contains a nil="true":
<cacheEntry>
<systemFK nil="true"/>
</cacheEntry>
I used the Flex DataService (webservice) wizard to create the service objects for the cacheEntry component. This object will be serialized later on a different webservice call and stored in a database.
I set a breakpoint on the set SystemFK method in the service object. It appears that the value passed in was an empty string!
Allowing this value to be an empty string will cause problems in the webservice implementation in Java on the other side. Since the database value was null it is expecting a null in return, If I avoid setting this value, the serviceObject should send back a null which will make the database happy.
My question is: How can I detect that a nil = true is present in the XML in order to avoid setting this value?
For some reason the ActionScript XML parsers don't know about Booleans. Without seeing the code that got generated for you, my guess is that somehow you're getting the string "true", instead of true, and that's what's causing your problem.
Make changes to the accessors to act as if #nil comes from the XML as a string, and then convert to Boolean manually.
My WCF uses XmlSerializer to serialize and deserialize fairly complex objects. Problem is, the corresponding XML payload value of one of the DateTime properties could be specified as either xs:date, xs:time or xs:dateTime values. I've noticed that when a time-only value (e.g. 16:55:00Z) is specified in the input XML the current date gets 'prepended' during deserialization (e.g. 2010-12-13T16:55:00Z). This obviously creates false data, I would rather have preferred DateTime.MinValue.
Is there a way I can control this behavior?
Thanks in advance
We use WCFDate to send the date part as xs:date.
See http://www.codeproject.com/Articles/182960/WCF-Support-for-xs-date for code.
Could someone here point me in the right direction about how I can override the serialization that occurs when my webservice is called?
Basically the end result I am aiming for is appending a TIMESTAMP to all objects returned from my webservice but only when the JavascriptSerializer is being used in my webservice as opposed to the XML serializer.
So for example below is a method that is contained in my webservice.
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function GetSettingData(ByVal Username As String, ByVal Password As String) As SettingList
When the webservice is called (As a GET request) at some point the JavascriptSerializer is invoked and my objects parsed and outputted as JSON. I am assuming that somewhere during that invokation I can insert my own version of the JavascriptSerializer and do as required?
Anyone able to guide me here?
(PS: I am well aware that I can return strings from all my webservices and perform the serialization as required in the actual webmethod call but I am looking for a 'better' solution then that (besides that would mean I would need different methods if I wanted to return XML))
You can use Stream or Message classes as return types, then you can implement your custom serialization. See for example How to set Json.Net as the default serializer for WCF REST service as an example.
I think i am lost with basics itself. What is the difference between these two. String object is an instance of String Class.
var guru:Object = new Object();
var guru:String = new String();
An object is a basic object. It has very few intrinsic properties and methods. More detail here
A string is an extended object that has the properties and methods relevant to strings. More detail here
If you're really not sure, I'd suggest looking up the answer here:
http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_11.html
Briefly, it states:
String data type
The String data type represents a
sequence of 16-bit characters. Strings
are stored internally as Unicode
characters, using the UTF-16 format.
Strings are immutable values, just as
they are in the Java programming
language. An operation on a String
value returns a new instance of the
string. The default value for a
variable declared with the String data
type is null. The value null is not
the same as the empty string (""),
even though they both represent the
absence of any characters.
Object data type
The Object data type is defined by the
Object class. The Object class serves
as the base class for all class
definitions in ActionScript. The
ActionScript 3.0 version of the Object
data type differs from that of
previous versions in three ways.
First, the Object data type is no
longer the default data type assigned
to variables with no type annotation.
Second, the Object data type no longer
includes the value undefined, which
used to be the default value of Object
instances. Third, in ActionScript 3.0,
the default value for instances of the
Object class is null.
If that doesn't satisfy your question, you're going to have to get more specific.
This guide can help you with basic Object Oriented questions regarding ActionScript 3.
The reference guide for String states that String inherits directly from Object.
The String class provides a bunch of useful methods that help with string manipulation on top of the few methods that Object provides (like toString()).
Trying to do an insert, I have:
jdbcTemplate.update("insert into....", new Object[]{foo.getId(), foo.getName()})
foo.getId() returns a long, and getName() a String.
I have "NUMBER" as the id type in Oracle, and varchar2 for the name field.
I'm getting SQLtype unknown problem.
the update method has a version where I do not have to put in the SQL types, but do I have to, and if so, how?
I'm assuming you mean the Spring Framework JdbcTemplate class. The JdbcTemplate methods will attempt to guess the java.sql.Type for value references, but apparently isn't guessing correctly in this case.
There are a couple of ways to include the type:
The JdbcTemplate.update(String, Object[]) [javadoc](http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jdbc/core/JdbcTemplate.html#update(java.lang.String, java.lang.Object[])) indicates that you can pass SqlParameterValue instances, consisting of the java.sql.Type and a value.
Alternatively, you can use JdbcTemplate.update(String, Object[], int[]) passing an array of java.sql.Type