XmlSerializer: Implicit convert int to bool

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
From an external system we receive via soap data in XML format. Boolean values are represented as integers (0=False,1=True).
In our data layer we use boolean. Now I want to deserialize this XML with the XmlSerializer, but I cant get it working.<br/>
Can somebody help me?

Example Code
<div style="color:Black; background-color:White
<pre><span style="color:Blue Public <span style="color:Blue Sub Test
<span style="color:Blue Dim lXml1 <span style="color:Blue As <span style="color:Blue String = <span style="color:#A31515 "<Patient NationalNumberValidated=""0""/>"
<span style="color:Blue Dim lPatient1 <span style="color:Blue As Patient = DeserializeObject(lXml1)

Console.WriteLine(<span style="color:#A31515 "Value of NationalNumberValidated:" & lPatient1.NationalNumberValidated.ToString)

<span style="color:Blue Dim lXml2 <span style="color:Blue As <span style="color:Blue String = <span style="color:#A31515 "<Patient NationalNumberValidated=""1""/>"
<span style="color:Blue Dim lPatient2 <span style="color:Blue As Patient = DeserializeObject(lXml1)

<span style="color:Green lPatient2.NationalNumberValidated is still not True
Console.WriteLine(<span style="color:#A31515 "Value of NationalNumberValidated:" & lPatient2.NationalNumberValidated.ToString)

<span style="color:Blue End <span style="color:Blue Sub

<span style="color:Blue Public <span style="color:Blue Function DeserializeObject(<span style="color:Blue ByVal xml <span style="color:Blue As <span style="color:Blue String) <span style="color:Blue As Patient

<span style="color:Blue Dim xs <span style="color:Blue As <span style="color:Blue New XmlSerializer(<span style="color:Blue GetType(Patient))

<span style="color:Blue Using lText <span style="color:Blue As <span style="color:Blue New System.IO.StringReader(xml)

<span style="color:Blue Return <span style="color:Blue CType(xs.Deserialize(lText), Patient)

<span style="color:Blue End <span style="color:Blue Using

<span style="color:Blue End <span style="color:Blue Function
[/code]

<br/>
<pre lang="x-vbnet <Serializable()> _
Public Class Patient

Private mBoolean As Boolean

<XmlAttribute()>
Public Property NationalNumberValidated() As Boolean
Get
Return mBoolean
End Get
Set(ByVal value As Boolean)
mBoolean = value
End Set
End Property

End Class[/code]
<br/>
<br/>
Thanx,
Arco

<br/>



View the full article
 
Back
Top