0

I have a pgsql view which returns list of records. One field of record is represented as json and deserialised to property List<ClassA> ClassAItems. However ClassAItems has also List<ClassB> ClassBItems and deserialisation doesnt not work at this level.

How to use Autquery or OrmLite is such case to process the query response so the items from ClassAItems will contain properly deserialised ClassBItems.

[Alias("vw_someview_with_json_field")]
public class ViewItem 
{
  public Id {get;set;} // it is properly deserialised
  public List<ClassA> ClassAItems {get;set;} // hierarchical json data
}

public class ClassA {
  public int Id {get;set;} // it is deserialised correctly
  public List<ClassB> ClassBItems {get;set;} // <--- here is the issue, it is not deserialised 
  
}
marcinn
  • 1,879
  • 2
  • 22
  • 46
  • OrmLite only supports deserializing its blobbed fields it serialized itself. Was this blobbed text field populated by OrmLite? If so can you provide a stand-alone repro (e.g. in a GitHub Repo) that I can run locally to repro the issue. – mythz Jul 19 '21 at 21:35
  • @mythz it is just json string not blob. I have tried on gist prepare a sample but for sql lite and simplified project it just work... https://gist.cafe/52aa621b313101523c8e6b28969cc0b6 – marcinn Jul 20 '21 at 18:33
  • ok I think the issue is that postgres column names have underscore separator for field names ... @mythz is there any option to set for particular classes on deserialising from string to use the postgres naming conventions i.e. field in db is "field_one" then is should be deserialised into field "FieldOne" – marcinn Jul 20 '21 at 18:54
  • 1
    I see `JsConfig.PropertyConvention = PropertyConvention.Lenient;` helps here – marcinn Jul 20 '21 at 19:08
  • Right you can set it to lenient to allow more relaxed fuzzy matching or annotate properties with `[DataMember(Name)]` to specify a different name they should use during serialization. – mythz Jul 20 '21 at 19:56

0 Answers0