title: Newsoft JSON .NET Deserializing to an Object with Private Properties in VB.net
body: <p>I am currently writing an API which is taking objects from a web service handling it in VB.net using the Newsoft JSON .NET library.</p>
  
  <p>I'm deserializing a JSON array called Vehicles into a list of vehicles.</p>
  
  <p>Here is the important code snippets:</p>
  
  <pre><code>Public Class VehicleList
      Public Vehicles() As Vehicle
  End Class
  
  Public Class Vehicle
      Public Property licence_plate_number As String
  End Class
  </code></pre>
  
  <p>Here we have a web client that grabs the json and put it into the objects.</p>
  
  <pre><code>Public Class dcVehicles
  
      Private Property _Vehicles As VehicleList
  
      Public ReadOnly Property Vehicle As Vehicle()
          Get
              Return _Vehicles.Vehicles
          End Get
      End Property
  
      Public Sub Refresh()
          _Vehicles = JsonConvert.DeserializeObject(Of VehicleList)(wcReply, jsSettings)
      End Sub
  End Class
  </code></pre>
  
  <p>There's slightly more to it (cut it down).
  So everything is working as intended, json net is creating an array of vehicles.</p>
  
  <p>I'm trying to achieve this with the properties in the vehicle class as private and read only, the applications using the api should not be able to set these.</p>
  
  <p>The problem is I've tried changing the public property in the vehicle class to keep the property private and allow readonly as below:</p>
  
  <pre><code>Public Class Vehicle
      Friend Property licence_plate_number As String
  
      Public ReadOnly Property RegistrationNumber As String
          Get
              Return licence_plate_number
          End Get
      End Property
  End Class
  </code></pre>
  
  <p>The problem I then get is that JSON.net is unable to populate the vehicles. All 3 classes are in the same namespace.
  So I tried licence_plate_number with the Friend/private access level modifier but still Json net is unable to populate the object.</p>
  
  <p>The only way is keeping it as Public.</p>
  
  <p>Does anyone have an idea for a work-around? Or is am I missing something simple?</p>
  
  <p>Thanks</p>