001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.databind.io.json;
007
008import com.fasterxml.jackson.core.JsonParser;
009
010import gov.nist.secauto.metaschema.core.model.IBoundObject;
011import gov.nist.secauto.metaschema.core.model.util.JsonUtil;
012import gov.nist.secauto.metaschema.databind.io.AbstractProblemHandler;
013import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelComplex;
014
015import java.io.IOException;
016import java.util.HashSet;
017import java.util.Set;
018
019public class DefaultJsonProblemHandler
020    extends AbstractProblemHandler
021    implements IJsonProblemHandler {
022  private static final String JSON_SCHEMA_FIELD_NAME = "$schema";
023  private static final Set<String> IGNORED_FIELD_NAMES;
024
025  static {
026    IGNORED_FIELD_NAMES = new HashSet<>();
027    IGNORED_FIELD_NAMES.add(JSON_SCHEMA_FIELD_NAME);
028  }
029
030  @Override
031  public boolean handleUnknownProperty(
032      IBoundDefinitionModelComplex classBinding,
033      IBoundObject targetObject,
034      String fieldName,
035      JsonParser parser) throws IOException {
036    boolean retval = false;
037    if (IGNORED_FIELD_NAMES.contains(fieldName)) {
038      JsonUtil.skipNextValue(parser);
039      retval = true;
040    }
041    return retval;
042  }
043}