l8nite / jsonapinet Goto Github PK
View Code? Open in Web Editor NEWAn easy-to-use, extensible C# library for JSON API documents.
License: GNU General Public License v2.0
An easy-to-use, extensible C# library for JSON API documents.
License: GNU General Public License v2.0
Imagine a simple relationship where a Foo
has a Boo
:
"data": [
{
"id": "1",
"type": "foos",
"relationships": {
"bar" : {
data: {
"type": "bars",
"id": "1"
}
}
}
}
What I'd like is to be able to deserialize Foo's "bar" relationship to the id, not to the full object.
See the comment for the Bar
property below:
class Foo
{
public int Id { get; set; }
public Bar Bar { get; set; } // instead, I would like to have this: public int BarId { get; set; }
}
class Bar
{
public int Id { get; set; }
}
How can I do this?
Hi,
I'm using JsonApiNet to deserialize a compound Json document, however the data types in the Json are singular rather than plural (e.g. "vendor" rather than "vendors"). This causes an error when calling JsonApi.ResourceFromDocument. Am I missing something? If I change the data types to plurals (i.e. vendors, addresses and contacts) it works fine. I do not have control over the generation of the Json.
I have attached the Json that does not work.
Many thanks,
Phil
how to map "name" complex type in attributes with my own class
class
`public class SubscriptionType
{
public string Id { get; set; }
public string BusinessModelType { get; set; }
//[JsonApiRelationship("name")] // [JsonApiAttribute("name")] //not working
public Name Name;
}`
public class Name { public string En { get; set; } public string Ur { get; set; } }
json
{ "data": [ { "attributes": { "business-model-type": "prepaid", "name": { "en": "Start prepaid", "ur": "Start Prepaid" } }, "id": "1", "links": { "self": "/api/v1/subscription-types/1" }, "relationships": { "billing-rate-plans": { "links": { "related": "/api/v1/subscription-types/1/billing-rate-plans" } } }, "type": "subscription-types" } ] }
It may be that I'd misunderstood project's readme.md, but I seem to fail to deserialize a fairly simple JSON API relationship case, which is as follows:
Please convert project to PCL type for Xamarin used.
Shaun, I submitted a PR for a bug fix that we have encountered. The issue is that if you pass a document that has an attribute that maps to a POCO property with no setter, a null reference exception occurs. We would expect the deserializer to just bypass the property. In this case the property with no setter has a getter from another property so when accessed, it actually has a value, just not the value in the original document.
Hi, we are evaluating to use this library in a commercial product but the GPL v2 license does not permit us to use it. Have you any plan to change the license in a MIT or Apache like one?
I require the update committed here for fixing null relations:
e688fcd
Could you please create a new nuget version?
var article = JsonApi.ResourceFromDocument
(json);Where should i write this code??
I have Foo
which has a relationship of several Boo
, but Boo
also has a relationship with Foo
.
This creates a stack overflow due to infinite recursion.
Is there a way to prevent this?
Enum properties are converted to strings, not to integers.
For example, if I have
class MyItem
{
public int Id { get; set; }
public MyItemStatus Status { get; set; }
}
enum MyItemStatus
{
Good,
Great
}
When serializing, it will write "good" or "great" not 0 or 1
The documentation says
Note: This is using Json.NET under the hood, so you can map complex objects from your "attributes" values using [JsonProperty], specify a custom JsonConverter on them, etc.!
so I tried this:
class MyItem
{
public int Id { get; set; }
[JsonConverter(typeof(IntEnumConverter)]
public MyItemStatus Status { get; set; }
}
but converter is not being called on serialization
Is it possible to make this package compatible for ASP.Net core (1.1)?
I love your library, I like how type and property resolvers work, especially since I don't like using attributes on POCO.
Any example how to serialize a resource object?
You mention in the README that "There are a couple alternative serializers for JSON API ".
So one is JsonApiMediaTypeFormatter, which is the other one?
I'm trying to wrap my head around JsonApiMediaTypeFormatter with no luck yet.
By the way I was able to convert the library into a PCL let me know if you're interested about that. It's pretty easy to do it, it's mostly about replacing reflection APIs with the ones from shared .NET.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.