This repository was archived by the owner on Jan 25, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " node-jsonapi-serializer" ,
3- "version" : " 2.1.0 " ,
3+ "version" : " 2.1.1 " ,
44 "description" : " GOintegro json-api extended serializer/deserializer" ,
55 "main" : " dist/index.js" ,
66 "types" : " dist/index.d.ts" ,
Original file line number Diff line number Diff line change 88 get ,
99 isEmpty ,
1010 isNull ,
11+ isNumber ,
1112 isObject ,
13+ isString ,
1214 isUndefined ,
1315 kebabCase ,
1416 keys ,
@@ -344,7 +346,7 @@ export class JSONAPISerializer {
344346 }
345347
346348 private serializeEntity (
347- data : JSONApiResource ,
349+ data : any ,
348350 config : SerializerConfig ,
349351 includedEntities : JSONApiResource [ ] ,
350352 serializedEntities : JSONApiResource [ ] ,
@@ -532,6 +534,8 @@ export class JSONAPISerializer {
532534
533535 if ( v ?. id ) {
534536 output . id = v . id . toString ( ) ;
537+ } else if ( isString ( v ) || isNumber ( v ) ) {
538+ output . id = v . toString ( ) ;
535539 }
536540 return output ;
537541 } ) ;
Original file line number Diff line number Diff line change 11import { JSONAPIDeserializer , JSONAPISerializer } from "../src" ;
22
3- test ( "JSONAPISerializer: compound nested" , async ( ) => {
3+ test ( "JSONAPISerializer:compound_nested" , async ( ) => {
4+
5+ class UserSerializer extends JSONAPISerializer {
6+ public serializerConfig = ( ) => {
7+ return {
8+ type : "users" ,
9+ attributes : [ ] ,
10+ } ;
11+ } ;
12+ }
13+
414 class PostSerializer extends JSONAPISerializer {
515 public serializerConfig = ( ) => {
616 return {
717 type : "posts" ,
818 attributes : [ "content" ] ,
919 relationships : {
1020 poll : { config : new PollSerializer ( ) . serializerConfig } ,
21+ mentions : { config : new UserSerializer ( ) . serializerConfig }
1122 } ,
1223 } ;
1324 } ;
@@ -35,6 +46,7 @@ test("JSONAPISerializer: compound nested", async () => {
3546
3647 const postData = {
3748 content : "Test" ,
49+ mentions : [ "1234" ] ,
3850 poll : {
3951 ttl : "3" ,
4052 options : [
@@ -54,6 +66,8 @@ test("JSONAPISerializer: compound nested", async () => {
5466 compound : true ,
5567 } ) ;
5668
69+ console . log ( JSON . stringify ( output ) ) ;
70+
5771 expect (
5872 output . data . relationships . poll . data . relationships . options . data [ 0 ] . attributes
5973 . title
You can’t perform that action at this time.
0 commit comments