@@ -722,22 +722,73 @@ describe("Testing JsonIgnore decorator", () => {
722722 expect ( testInstance . state ) . toBe ( "old" ) ;
723723 } ) ;
724724
725- it ( "Testing DeserializationConfig" , ( ) => {
726- class Event {
725+ describe ( "DeserializationConfig" , ( ) => {
726+ it ( "{ ignoreNameMetadata: true } should use property name" , ( ) => {
727+ class Event {
728+ @JsonProperty ( )
729+ id : number = undefined ;
730+ @JsonProperty ( { name : "geo-location" } )
731+ location = "old" ;
732+ }
733+
734+ const json = {
735+ id : "1" ,
736+ location : "Canberra" ,
737+ } ;
738+
739+ const testInstance : Event = ObjectMapper . deserialize ( Event , json , {
740+ ignoreNameMetadata : true ,
741+ } ) ;
742+ expect ( testInstance . location ) . toBe ( "Canberra" ) ;
743+ } ) ;
744+
745+ it ( "{ ignoreNameMetadata: true } should use name metadata during serialization" , ( ) => {
746+ class Event {
747+ @JsonProperty ( )
748+ id : number = undefined ;
749+ @JsonProperty ( { name : "geo-location" } )
750+ location = "old" ;
751+ }
752+
753+ const json = {
754+ id : "1" ,
755+ location : "Canberra" ,
756+ } ;
757+
758+ const testInstance : Event = ObjectMapper . deserialize ( Event , json , {
759+ ignoreNameMetadata : true ,
760+ } ) ;
761+
762+ const serialized = ObjectMapper . serialize ( testInstance ) ;
763+ expect ( serialized ) . toBe ( '{"id":"1","geo-location":"Canberra"}' ) ;
764+ } ) ;
765+ } ) ;
766+
767+ it ( "{ ignoreNameMetadata: true } should work with array serialization" , ( ) => {
768+ class DeserializeComplexTypeArrayTest {
727769 @JsonProperty ( )
728- id : number = undefined ;
729- @JsonProperty ( { name : "geo-location" } )
730- location = "old" ;
770+ storeName : string = undefined ;
771+
772+ @JsonProperty ( { name : "AVAILABLE_AT" } )
773+ availableAt : String [ ] = undefined ;
731774 }
732775
733776 const json = {
734- id : "1 " ,
735- location : "Canberra" ,
777+ storeName : "PizzaHut " ,
778+ availableAt : [ "2000" , "3000" , "4000" , "5000" ] ,
736779 } ;
737780
738- const testInstance : Event = ObjectMapper . deserialize ( Event , json , {
739- ignoreNameMetadata : true ,
740- } ) ;
741- expect ( testInstance . location ) . toBe ( "Canberra" ) ;
781+ const testInstance = ObjectMapper . deserialize (
782+ DeserializeComplexTypeArrayTest ,
783+ json ,
784+ {
785+ ignoreNameMetadata : true ,
786+ }
787+ ) ;
788+
789+ const serialized = ObjectMapper . serialize ( testInstance ) ;
790+ expect ( serialized ) . toBe (
791+ '{"storeName":"PizzaHut","AVAILABLE_AT":["2000","3000","4000","5000"]}'
792+ ) ;
742793 } ) ;
743794} ) ;
0 commit comments