@@ -112,6 +112,11 @@ public class POJOPropertiesCollector
112
112
113
113
protected LinkedList <AnnotatedMember > _anySetterField ;
114
114
115
+ /**
116
+ * Method(s) annotated with 'JsonKey' annotation
117
+ */
118
+ protected LinkedList <AnnotatedMember > _jsonKeyAccessors ;
119
+
115
120
/**
116
121
* Method(s) marked with 'JsonValue' annotation
117
122
*<p>
@@ -194,6 +199,23 @@ public Map<Object, AnnotatedMember> getInjectables() {
194
199
return _injectables ;
195
200
}
196
201
202
+ public AnnotatedMember getJsonKeyAccessor () {
203
+ if (!_collected ) {
204
+ collectAll ();
205
+ }
206
+ // If @JsonKey defined, must have a single one
207
+ if (_jsonKeyAccessors != null ) {
208
+ if (_jsonKeyAccessors .size () > 1 ) {
209
+ reportProblem ("Multiple 'as-value' properties defined (%s vs %s)" ,
210
+ _jsonKeyAccessors .get (0 ),
211
+ _jsonKeyAccessors .get (1 ));
212
+ }
213
+ // otherwise we won't greatly care
214
+ return _jsonKeyAccessors .get (0 );
215
+ }
216
+ return null ;
217
+ }
218
+
197
219
/**
198
220
* @since 2.9
199
221
*/
@@ -391,6 +413,13 @@ protected void _addFields(Map<String, POJOPropertyBuilder> props)
391
413
final boolean transientAsIgnoral = _config .isEnabled (MapperFeature .PROPAGATE_TRANSIENT_MARKER );
392
414
393
415
for (AnnotatedField f : _classDef .fields ()) {
416
+ // @JsonKey?
417
+ if (Boolean .TRUE .equals (ai .hasAsKey (f ))) {
418
+ if (_jsonKeyAccessors == null ) {
419
+ _jsonKeyAccessors = new LinkedList <>();
420
+ }
421
+ _jsonKeyAccessors .add (f );
422
+ }
394
423
// @JsonValue?
395
424
if (Boolean .TRUE .equals (ai .hasAsValue (f ))) {
396
425
if (_jsonValueAccessors == null ) {
@@ -593,6 +622,14 @@ protected void _addGetterMethod(Map<String, POJOPropertyBuilder> props,
593
622
_anyGetters .add (m );
594
623
return ;
595
624
}
625
+ // @JsonKey?
626
+ if (Boolean .TRUE .equals (ai .hasAsKey (m ))) {
627
+ if (_jsonKeyAccessors == null ) {
628
+ _jsonKeyAccessors = new LinkedList <>();
629
+ }
630
+ _jsonKeyAccessors .add (m );
631
+ return ;
632
+ }
596
633
// @JsonValue?
597
634
if (Boolean .TRUE .equals (ai .hasAsValue (m ))) {
598
635
if (_jsonValueAccessors == null ) {
0 commit comments