@@ -15,6 +15,7 @@ namespace Microsoft.ML.Tokenizers
1515    /// This should only be used with a Ptr/Length for querying. For storing in a dictionary, this should 
1616    /// always be used with a string. 
1717    /// </remarks> 
18+     [ JsonConverter ( typeof ( StringSpanOrdinalKeyConverter ) ) ] 
1819    internal  readonly  unsafe  struct  StringSpanOrdinalKey  :  IEquatable < StringSpanOrdinalKey > 
1920    { 
2021        public  readonly  char *  Ptr ; 
@@ -124,12 +125,14 @@ internal void Set(string k, TValue v)
124125        } 
125126    } 
126127
128+     [ JsonConverter ( typeof ( VocabularyConverter ) ) ] 
129+     internal  sealed  class  Vocabulary  :  Dictionary < StringSpanOrdinalKey ,  ( int ,  string ) > ; 
130+ 
127131    /// <summary> 
128132    /// Custom JSON converter for <see cref="StringSpanOrdinalKey"/>. 
129133    /// </summary> 
130134    internal  sealed  class  StringSpanOrdinalKeyConverter  :  JsonConverter < StringSpanOrdinalKey > 
131135    { 
132-         public  static StringSpanOrdinalKeyConverter  Instance  {  get ;  }  =  new  StringSpanOrdinalKeyConverter ( ) ; 
133136        public  override  StringSpanOrdinalKey  ReadAsPropertyName ( ref  Utf8JsonReader  reader ,  Type  typeToConvert ,  JsonSerializerOptions  options )  => 
134137            new  StringSpanOrdinalKey ( reader . GetString ( ) ! ) ; 
135138
@@ -140,13 +143,11 @@ public override void WriteAsPropertyName(Utf8JsonWriter writer, StringSpanOrdina
140143        public  override  void  Write ( Utf8JsonWriter  writer ,  StringSpanOrdinalKey  value ,  JsonSerializerOptions  options )  =>  writer . WriteStringValue ( value . Data ! ) ; 
141144    } 
142145
143-     internal  class  StringSpanOrdinalKeyCustomConverter  :  JsonConverter < Dictionary < StringSpanOrdinalKey ,   ( int ,   string ) > > 
146+     internal  class  VocabularyConverter  :  JsonConverter < Vocabulary > 
144147    { 
145-         public  static StringSpanOrdinalKeyCustomConverter  Instance  {  get ;  }  =  new  StringSpanOrdinalKeyCustomConverter ( ) ; 
146- 
147-         public  override  Dictionary < StringSpanOrdinalKey ,  ( int ,  string ) >  Read ( ref  Utf8JsonReader  reader ,  Type  typeToConvert ,  JsonSerializerOptions  options ) 
148+         public  override  Vocabulary  Read ( ref  Utf8JsonReader  reader ,  Type  typeToConvert ,  JsonSerializerOptions  options ) 
148149        { 
149-             var  dictionary  =  new  Dictionary < StringSpanOrdinalKey ,   ( int ,   string ) > ( ) ; 
150+             var  dictionary  =  new  Vocabulary ( ) ; 
150151            while  ( reader . Read ( ) ) 
151152            { 
152153                if  ( reader . TokenType  ==  JsonTokenType . EndObject ) 
@@ -165,7 +166,7 @@ internal class StringSpanOrdinalKeyCustomConverter : JsonConverter<Dictionary<St
165166            throw  new  JsonException ( "Invalid JSON." ) ; 
166167        } 
167168
168-         public  override  void  Write ( Utf8JsonWriter  writer ,  Dictionary < StringSpanOrdinalKey ,   ( int ,   string ) >  value ,  JsonSerializerOptions  options )  =>  throw  new  NotImplementedException ( ) ; 
169+         public  override  void  Write ( Utf8JsonWriter  writer ,  Vocabulary  value ,  JsonSerializerOptions  options )  =>  throw  new  NotImplementedException ( ) ; 
169170    } 
170171
171172    /// <summary> 
0 commit comments