/// <summary> /// Read the content as a JSONAPI response object. /// </summary> /// <param name="httpContent">The HTTP content to read the JSONAPI response from.</param> /// <param name="serializerOptions">The options to use for the serializer.</param> /// <param name="cache">The entity cache to use for resolving existing instances in the object graph.</param> /// <returns>The JSONAPI response element that was read from the stream in the HTTP content.</returns> public static Task <TEntity> ReadAsJsonApiAsync <TEntity>( this HttpContent httpContent, JsonApiSerializerOptions serializerOptions, IJsonApiEntityCache cache) { var serializer = new JsonApiSerializer(serializerOptions); return(httpContent.ReadAsJsonApiAsync <TEntity>(serializer, cache)); }
/// <summary> /// Constructor. /// </summary> /// <param name="serializerOptions">The serializer options.</param> public JsonApiOutputFormatter(JsonApiSerializerOptions serializerOptions) : base(JsonApiMediaTypeName, serializerOptions.ContractResolver, serializerOptions.FieldNamingStrategy) { _serializerOptions = serializerOptions; }
/// <summary> /// Serialize the entities to a content string. /// </summary> /// <param name="entities">The entities to serialize.</param> /// <param name="serializerOptions">The serializer options.</param> /// <returns>The string that represents the serialized version of the entity.</returns> static string SerializeMany(IEnumerable <TEntity> entities, JsonApiSerializerOptions serializerOptions) { var serializer = new JsonApiSerializer(serializerOptions); return(serializer.SerializeMany(entities).Stringify()); }
/// <summary> /// Serialize the entity to a content string. /// </summary> /// <param name="entity">The entity to serialize.</param> /// <param name="serializerOptions">The serializer options.</param> /// <returns>The string that represents the serialized version of the entity.</returns> static string SerializeEntity(TEntity entity, JsonApiSerializerOptions serializerOptions) { var serializer = new JsonApiSerializer(serializerOptions); return(serializer.SerializeEntity(entity).Stringify()); }
/// <summary> /// Constructor. /// </summary> /// <param name="entities">The entities to serialize.</param> /// <param name="serializerOptions">The serializer options.</param> public JsonApiContent(IEnumerable <TEntity> entities, JsonApiSerializerOptions serializerOptions) : base(SerializeMany(entities, serializerOptions), Encoding.UTF8, MediaTypeName) { }
/// <summary> /// Constructor. /// </summary> /// <param name="entity">The entity to serialize.</param> /// <param name="serializerOptions">The serializer options.</param> public JsonApiContent(TEntity entity, JsonApiSerializerOptions serializerOptions) : base(SerializeEntity(entity, serializerOptions), Encoding.UTF8, MediaTypeName) { }
/// <summary> /// Gets a single entity. /// </summary> /// <typeparam name="TEntity">The element type.</typeparam> /// <param name="serializerOptions">The serializer options.</param> /// <param name="cache">The entity cache to use for resolving existing instances in the object graph.</param> /// <returns>The list of JSON API entities.</returns> public TEntity Get <TEntity>(JsonApiSerializerOptions serializerOptions, IJsonApiEntityCache cache) { return(Get <TEntity>(new JsonApiSerializer(serializerOptions), cache)); }
/// <summary> /// Gets a list of entities. /// </summary> /// <typeparam name="TEntity">The element type.</typeparam> /// <param name="serializerOptions">The serializer options.</param> /// <param name="cache">The entity cache to use for resolving existing instances in the object graph.</param> /// <returns>The list of JSON API entities.</returns> public IEnumerable <TEntity> GetMany <TEntity>(JsonApiSerializerOptions serializerOptions, IJsonApiEntityCache cache) { return(GetMany <TEntity>(new JsonApiSerializer(serializerOptions), cache)); }
/// <summary> /// Read the content as a JSONAPI response object. /// </summary> /// <param name="httpContent">The HTTP content to read the JSONAPI response from.</param> /// <param name="serializerOptions">The serializer options.</param> /// <returns>The JSONAPI response element that was read from the stream in the HTTP content.</returns> public static Task <List <TEntity> > ReadAsJsonApiManyAsync <TEntity>(this HttpContent httpContent, JsonApiSerializerOptions serializerOptions) { return(httpContent.ReadAsJsonApiManyAsync <TEntity>(serializerOptions, new JsonApiEntityCache())); }