1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.databind.io.json;
7   
8   import com.fasterxml.jackson.core.JsonParser;
9   
10  import gov.nist.secauto.metaschema.core.model.IBoundObject;
11  import gov.nist.secauto.metaschema.core.model.util.JsonUtil;
12  import gov.nist.secauto.metaschema.databind.io.AbstractProblemHandler;
13  import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelComplex;
14  
15  import java.io.IOException;
16  import java.util.HashSet;
17  import java.util.Set;
18  
19  public class DefaultJsonProblemHandler
20      extends AbstractProblemHandler
21      implements IJsonProblemHandler {
22    private static final String JSON_SCHEMA_FIELD_NAME = "$schema";
23    private static final Set<String> IGNORED_FIELD_NAMES;
24  
25    static {
26      IGNORED_FIELD_NAMES = new HashSet<>();
27      IGNORED_FIELD_NAMES.add(JSON_SCHEMA_FIELD_NAME);
28    }
29  
30    @Override
31    public boolean handleUnknownProperty(
32        IBoundDefinitionModelComplex classBinding,
33        IBoundObject targetObject,
34        String fieldName,
35        JsonParser parser) throws IOException {
36      boolean retval = false;
37      if (IGNORED_FIELD_NAMES.contains(fieldName)) {
38        JsonUtil.skipNextValue(parser);
39        retval = true;
40      }
41      return retval;
42    }
43  }