Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (c) 2012, Francis Galiegue <>
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the Lesser GNU General Public License as
   * published by the Free Software Foundation, either version 3 of the
   * License, or (at your option) any later version.
   * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * Lesser GNU General Public License for more details.
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <>.
 package com.github.fge.jsonschema.util;
 import java.util.Map;

Enumeration for the different types of JSON instances which can be encountered.

In addition to what the JSON RFC defines, JSON Schema has an integer type, which is a numeric value without any fraction or exponent part.

 public enum NodeType
Array nodes
Boolean nodes
Integer nodes
Number nodes (ie, decimal numbers)
Object nodes
Null nodes
String nodes

The name for this type, as encountered in a JSON schema
     private final String name;

Reverse map to find a node type out of this type's name
     private static final Map<StringNodeTypeNAME_MAP;

     private static final Map<JsonTokenNodeTypeTOKEN_MAP
         = new EnumMap<JsonTokenNodeType>(JsonToken.class);
     static {
         final ImmutableMap.Builder<StringNodeTypebuilder
             = ImmutableMap.builder();
         for (final NodeType type: NodeType.values())
    NodeType(final String name)
        this. = name;
    public String toString()
        return ;

Given a type name, return the corresponding node type

name the type name
the node type, or null if not found
    public static NodeType fromName(final String name)
        return .get(name);

Given a com.fasterxml.jackson.databind.JsonNode as an argument, return its type. The argument MUST NOT BE NULL, and MUST NOT be a com.fasterxml.jackson.databind.node.MissingNode

node the node to determine the type of
the type for this node
    public static NodeType getNodeType(final JsonNode node)
        final JsonToken token = node.asToken();
        final NodeType ret = .get(token);
        Preconditions.checkNotNull(ret"unhandled token type " + token);
        return ret;
New to GrepCode? Check out our FAQ X