You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand that Marten doesn't support the Json serialization attributes on properties except the [JsonIgnore] one. Here is the use case I'm struggling to finding a workaround though.
I use an external web api which provides the OpenAPI schema. For example, something like this.
In order to access the web api I use NSwag.CodeGeneration.CSharp nuget package or any other NSwag tools for generating the C# classes. I tried different settings, but NSwag always adds the JsonPropertyName attribute to every property to match the OpenAPI specification. I don't want to reimplement all those records manually and I would like to be able to store the object to Marten. It is stored correctly, but when I use LINQ to filter or sort by a property the C# property name and casing is used in the SQL which obviously is not matched to the Json. Would it be possible while generating the SQL instead of just using the property name to try to pull the [JsonPropertyName] attribute for that property and use it if it's specified? Here is an example of the code generated by NSwag. Please let me know, if there is any workaround available in the short-term, besides just manually creating the classes?
/// <summary>/// This type is used by the <strong>taxIdentifier</strong> container that is returned in <strong>getOrder</strong>. The <strong>taxIdentifier</strong> container consists of taxpayer identification information for buyers from Italy, Spain, or Guatemala. It is currently only returned for orders occurring on the eBay Italy or eBay Spain marketplaces.<br><br><span class="tablenote"><strong>Note:</strong> Currently, the <strong>taxIdentifier</strong> container is only returned in <strong>getOrder</strong> and not in <strong>getOrders</strong>. So, if a seller wanted to view a buyer's tax information for a particular order returned in <strong>getOrders</strong>, that seller would need to use the <strong>orderId</strong> value for that particular order, and then run a <strong>getOrder</strong> call against that order ID. </span>/// </summary>[System.CodeDom.Compiler.GeneratedCode("NJsonSchema","13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v10.0.0.0))")]publicpartialrecordTaxIdentifier{[System.Text.Json.Serialization.JsonConstructor]publicTaxIdentifier(string@issuingCountry,string@taxIdentifierType,string@taxpayerId){this.TaxpayerId =@taxpayerId;this.TaxIdentifierType =@taxIdentifierType;this.IssuingCountry =@issuingCountry;}/// <summary>/// This value is the unique tax ID associated with the buyer. The type of tax identification is shown in the <strong>taxIdentifierType</strong> field./// </summary>[System.Text.Json.Serialization.JsonPropertyName("taxpayerId")][System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]publicstringTaxpayerId{get;init;}/// <summary>/// This enumeration value indicates the type of tax identification being used for the buyer. The different tax types are defined in the <strong>TaxIdentifierTypeEnum</strong> type. For implementation help, refer to <a href='https://developer.ebay.com/api-docs/sell/fulfillment/types/sel:TaxIdentifierTypeEnum'>eBay API documentation</a>/// </summary>[System.Text.Json.Serialization.JsonPropertyName("taxIdentifierType")][System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]publicstringTaxIdentifierType{get;init;}/// <summary>/// This two-letter code indicates the country that issued the buyer's tax ID. The country that the two-letter code represents can be found in the <strong>CountryCodeEnum</strong> type, or in the <a href="https://www.iso.org/iso-3166-country-codes.html ">ISO 3166</a> standard. For implementation help, refer to <a href='https://developer.ebay.com/api-docs/sell/fulfillment/types/ba:CountryCodeEnum'>eBay API documentation</a>/// </summary>[System.Text.Json.Serialization.JsonPropertyName("issuingCountry")][System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]publicstringIssuingCountry{get;init;}private System.Collections.Generic.IDictionary<string,object>_additionalProperties;[System.Text.Json.Serialization.JsonExtensionData]public System.Collections.Generic.IDictionary<string,object> AdditionalProperties
{get{return_additionalProperties??(_additionalProperties=new System.Collections.Generic.Dictionary<string,object>());}set{_additionalProperties=value;}}}
The text was updated successfully, but these errors were encountered:
I understand that Marten doesn't support the Json serialization attributes on properties except the [JsonIgnore] one. Here is the use case I'm struggling to finding a workaround though.
I use an external web api which provides the OpenAPI schema. For example, something like this.
In order to access the web api I use
NSwag.CodeGeneration.CSharp
nuget package or any otherNSwag
tools for generating the C# classes. I tried different settings, but NSwag always adds theJsonPropertyName
attribute to every property to match the OpenAPI specification. I don't want to reimplement all those records manually and I would like to be able to store the object to Marten. It is stored correctly, but when I use LINQ to filter or sort by a property the C# property name and casing is used in the SQL which obviously is not matched to the Json. Would it be possible while generating the SQL instead of just using the property name to try to pull the [JsonPropertyName] attribute for that property and use it if it's specified? Here is an example of the code generated by NSwag. Please let me know, if there is any workaround available in the short-term, besides just manually creating the classes?The text was updated successfully, but these errors were encountered: