Search code examples
.netjsonfastjson

FastJson encoder bug


I have a class Sale which holds sale data, and then i have a property in the Sale class which is A list of SaleItem class.

Sale
-date
-SaleItems <-- List(Of SaleItem)
-total

the SaleItem class

SaleItem
-productID
-amt
-qty

when I convert to Json string and debugged print to output. the SaleItems was not encoded,simply missing.

what am I doing wrong,or could this be a bug?

EDIT

The Sale class

Public Class Sale
    Private _Paid As Decimal
    Private _ListSaleItems As List(Of SaleItem)

    Public Sub New()
        ClearSaleItem()
    End Sub

    Public ReadOnly Property SaleItems() As List(Of SaleItem)
        Get
            Return _ListSaleItems
        End Get
    End Property


    Public Property Paid() As Decimal
        Get
            Return _Paid
        End Get
        Set
            _Paid = value
        End Set
    End Property


    Public Sub ClearSaleItem()
        _ListSaleItems = New List(Of SaleItem)()
    End Sub


    Public Function AddSaleItem(value As SaleItem) As Decimal
        If value Is Nothing Then
            Throw New ApplicationException("SaleItem cannot be empty")
        End If
        _ListSaleItems.Add(value)
    End Function
End Class

The Saleitem Class

Public Class SaleItem
    Private _ID As Int32
    Private _Quantity As Int32
    Private _SellPrice As Decimal


    Public Sub New()
        _Quantity = 0
        _SellPrice = 0
    End Sub

    Public Property SellPrice() As Decimal
        Get
            Return _SellPrice
        End Get
        Set
            _SellPrice = value
        End Set
    End Property

    Public Property Quantity() As Int32
        Get
            Return _Quantity
        End Get
        Set
            _Quantity = value
        End Set
    End Property

End Class

The code i am using to convert is

sockClient.Send(fastJSON.JSON.ToJSON(ObjSales))

Solution

  • Thank you for your contribution, it happens that the dll coder gave me the solution

    I have to change the Saleitems property of Sale from Readonly to Read/Write property

    Public Property SaleItems() As List(Of SaleItem)
                Get
                    Return Me.listSaleItems
                End Get
    Set(value as List(Of SaleItem))
                    listSaleItems = value 
                End Get
            End Property
    

    Thanks