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