Deserializes the specified json into a {@link Map}. If you have the Json in a {@link Reader}
form instead of a {@link String}, use {@link #fromJson(Reader)} instead.
514807
public Map<String, Object> fromJson(String json) throws IOException {
    if (json == null) {
      throw new IllegalArgumentException("json == null");
    }
    if (json.length() == 0) {
      throw new IllegalArgumentException("json empty");
    }
    return fromJson(new StringReader(json));
  }
402869
public JsonReader newJsonReader( String input ) {
        JsonReader reader = new NonBufferedJsonReader( input );
        reader.setLenient( true );
        return reader;
    }
452179
public static Object jsonValue(JsonReader reader) throws IOException {
        switch (reader.peek()) {
            case STRING:
                return reader.nextString();
            case BOOLEAN:
                return reader.nextBoolean();
            case NUMBER:
                try {
                    return reader.nextLong();
                } catch (NumberFormatException nfex) {
                    return reader.nextDouble();
                }
            case BEGIN_ARRAY:
                ArrayList<Object> list = new ArrayList<>();
                reader.beginArray();
                while (reader.peek() != JsonToken.END_ARRAY) {
                    list.add(jsonValue(reader));
                }
                reader.endArray();
                return list;
            case BEGIN_OBJECT:
                return jsonMap(reader);
            default:
                reader.skipValue();
        }
        return null;
    }
346887
public static <T extends BaseBo> T fromJson(String json, Class<T> clazz) {
        return fromJson(json, clazz, null);
    }
326042
@Override
    public final T deserializeInline( final JsonReader reader, final JsonDeserializationContext ctx, JsonDeserializerParameters params,
                                      IdentityDeserializationInfo identityInfo, TypeDeserializationInfo typeInfo, String type,
                                      Map<String, String> bufferedProperties ) {
        final boolean ignoreUnknown = params.isIgnoreUnknown() || isDefaultIgnoreUnknown();
        final Set<String> ignoredProperties;
        if ( null == params.getIgnoredProperties() ) {
            ignoredProperties = defaultIgnoredProperties;
        } else {
            ignoredProperties = new HashSet<String>( defaultIgnoredProperties );
            ignoredProperties.addAll( params.getIgnoredProperties() );
        }

        // we will remove the properties read from this list and check at the end it's empty
        Set<String> requiredPropertiesLeft = requiredProperties.isEmpty() ? Collections
                .<String>emptySet() : new HashSet<String>( requiredProperties );

        // we first look for identity. It can also buffer properties if it is not in current reader position.
        Object id = null;
        Map<String, Object> bufferedPropertiesValues = null;
        if ( null != identityInfo ) {
            JsonReader identityReader = null;

            // we look if it has not been already buffered
            String propertyValue = null;

            // we fisrt look if the identity property has not been read already
            if ( null != bufferedProperties ) {
                propertyValue = bufferedProperties.remove( identityInfo.getPropertyName() );
            }

            if ( null != propertyValue ) {
                identityReader = ctx.newJsonReader( propertyValue );
            } else {
                // we search for the identity property
                while ( JsonToken.NAME.equals( reader.peek() ) ) {
                    String name = reader.nextName();

                    if ( ignoredProperties.contains( name ) ) {
                        reader.skipValue();
                        continue;
                    }

                    if ( identityInfo.getPropertyName().equals( name ) ) {
                        identityReader = reader;
                        break;
                    } else {
                        if ( null == bufferedProperties ) {
                            bufferedProperties = new HashMap<String, String>();
                        }
                        bufferedProperties.put( name, reader.nextValue() );
                    }
                }
            }

            if ( null != identityReader ) {
                if ( identityInfo.isProperty() ) {
                    HasDeserializerAndParameters propertyDeserializer = deserializers.get( identityInfo.getPropertyName() );
                    if ( null == propertyDeserializer ) {
                        // the identity property is defined in constructor
                        propertyDeserializer = instanceBuilder.getParametersDeserializer().get( identityInfo.getPropertyName() );
                        id = propertyDeserializer.getDeserializer().deserialize( identityReader, ctx );
                        bufferedPropertiesValues = new HashMap<String, Object>( 1 );
                        bufferedPropertiesValues.put( identityInfo.getPropertyName(), id );
                    } else {
                        id = propertyDeserializer.getDeserializer().deserialize( identityReader, ctx );
                    }
                } else {
                    id = identityInfo.readId( identityReader, ctx );
                }
            }
        }

        // we first instantiate the bean. It might buffer properties if there are properties required for constructor and they are not in
        // first position
        Instance<T> instance = instanceBuilder.newInstance( reader, ctx, params, bufferedProperties, bufferedPropertiesValues );

        T bean = instance.getInstance();
        bufferedProperties = instance.getBufferedProperties();

        // we save the instance if we have an id
        if ( null != id ) {
            if ( identityInfo.isProperty() ) {
                BeanPropertyDeserializer propertyDeserializer = deserializers.get( identityInfo.getPropertyName() );
                if ( null != propertyDeserializer ) {
                    propertyDeserializer.setValue( bean, id, ctx );
                }
            }
            ctx.addObjectId( identityInfo.newIdKey( id ), bean );
        }

        // we flush any buffered properties
        flushBufferedProperties( bean, bufferedProperties, requiredPropertiesLeft, ctx, ignoreUnknown, ignoredProperties );

        // in case there is a property that need the type info
        if ( null != typeInfo && null != typeInfo.getPropertyName() && null != type ) {
            BeanPropertyDeserializer deserializer = getPropertyDeserializer( typeInfo.getPropertyName(), ctx, true );
            if ( null != deserializer ) {
                deserializer.setValue( bean, type, ctx );
            }
        }

        while ( JsonToken.NAME.equals( reader.peek() ) ) {
            String propertyName = reader.nextName();

            requiredPropertiesLeft.remove( propertyName );

            if ( ignoredProperties.contains( propertyName ) ) {
                reader.skipValue();
                continue;
            }

            BeanPropertyDeserializer<T, ?> property = getPropertyDeserializer( propertyName, ctx, ignoreUnknown );
            if ( null != property ) {
                property.deserialize( reader, bean, ctx );
            } else if ( null != anySetterDeserializer ) {
                anySetterDeserializer.deserialize( reader, bean, propertyName, ctx );
            } else {
                reader.skipValue();
            }
        }

        if ( !requiredPropertiesLeft.isEmpty() ) {
            throw ctx.traceError( "Required properties are missing : " + requiredPropertiesLeft, reader );
        }
        return bean;
    }
819179
private Map deserializeMap(File file) {
        Map<?,?> map;
        try(ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)))) {
            map = (Map<?,?>) is.readObject();
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
            return null;
        }
        return map;
    }
857065
@SuppressWarnings("unchecked")
    private static Map<String, String> matdescFromJson(String json) {
        Map<String, String> map = Jackson.fromJsonString(json, Map.class);
        return map == null ? null : Collections.unmodifiableMap(map);
    }
678542
public static StateMachine.Builder fromJson(String json) {
        try {
            return MAPPER.readValue(json, StateMachine.Builder.class);
        } catch (IOException e) {
            throw new SdkClientException(
                    String.format("Could not deserialize state machine.\n%s", json), e);
        }
    }
563143
private Map<String, Object> getMapFromJSON(String json) {
        Map<String, Object> propMap = new HashMap<String, Object>();
        ObjectMapper mapper = new ObjectMapper();

        // Initialize string if empty
        if (json == null || json.length() == 0) {
            json = "{}";
        }

        try {
            // Convert string
            propMap = mapper.readValue(json, new TypeReference<HashMap<String, Object>>(){});
        } catch (Exception e) {
            ;
        }
        return propMap;
    }
613373
public JsonReader createReader(Reader reader) {
        return new JsonReader(reader, jsonObjectFactory, jsonArrayFactory, objectMapper, typeAdapters);
    }
673728
public V deserialize( JsonReader reader, JsonDeserializationContext ctx ) {
        return getDeserializer().deserialize( reader, ctx, getParameters() );
    }
1250407
public static ScanResult fromJSON(final String json) {
        final Matcher matcher = Pattern.compile("\\{[\\n\\r ]*\"format\"[ ]?:[ ]?\"([^\"]+)\"").matcher(json);
        if (!matcher.find()) {
            throw new IllegalArgumentException("JSON is not in correct format");
        }
        if (!CURRENT_SERIALIZATION_FORMAT.equals(matcher.group(1))) {
            throw new IllegalArgumentException(
                    "JSON was serialized in a different format from the format used by the current version of "
                            + "ClassGraph -- please serialize and deserialize your ScanResult using "
                            + "the same version of ClassGraph");
        }

        // Deserialize the JSON
        final SerializationFormat deserialized = JSONDeserializer.deserializeObject(SerializationFormat.class,
                json);
        if (!deserialized.format.equals(CURRENT_SERIALIZATION_FORMAT)) {
            // Probably the deserialization failed before now anyway, if fields have changed, etc.
            throw new IllegalArgumentException("JSON was serialized by newer version of ClassGraph");
        }

        // Perform a new "scan" with performScan set to false, which resolves all the ClasspathElement objects
        // and scans classpath element paths (needed for classloading), but does not scan the actual classfiles
        final ClassGraph classGraph = new ClassGraph();
        classGraph.scanSpec = deserialized.scanSpec;
        classGraph.scanSpec.performScan = false;
        if (classGraph.scanSpec.overrideClasspath == null) {
            // Use the same classpath as before, if classpath was not overridden
            classGraph.overrideClasspath(deserialized.classpath);
        }
        final ScanResult scanResult = classGraph.scan();
        scanResult.rawClasspathEltOrderStrs = deserialized.classpath;
        scanResult.scanSpec.performScan = true;

        // Set the fields related to ClassInfo in the new ScanResult, based on the deserialized JSON 
        scanResult.scanSpec = deserialized.scanSpec;
        scanResult.classNameToClassInfo = new HashMap<>();
        if (deserialized.classInfo != null) {
            for (final ClassInfo ci : deserialized.classInfo) {
                scanResult.classNameToClassInfo.put(ci.getName(), ci);
                ci.setScanResult(scanResult);
            }
        }
        scanResult.moduleNameToModuleInfo = new HashMap<>();
        if (deserialized.moduleInfo != null) {
            for (final ModuleInfo mi : deserialized.moduleInfo) {
                scanResult.moduleNameToModuleInfo.put(mi.getName(), mi);
            }
        }
        scanResult.packageNameToPackageInfo = new HashMap<>();
        if (deserialized.packageInfo != null) {
            for (final PackageInfo pi : deserialized.packageInfo) {
                scanResult.packageNameToPackageInfo.put(pi.getName(), pi);
            }
        }

        // Index Resource and ClassInfo objects 
        scanResult.indexResourcesAndClassInfo();

        scanResult.isObtainedFromDeserialization = true;
        return scanResult;
    }
1338628
@Override
  public void from(Map<KEY, VALUE> map) {
    getMap().putAll(nullSafeMap(map));
  }
734848
public static Map toMap(String json) {
        try {
            return mapper.readValue(json, Map.class);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
1017948
@SuppressWarnings("unchecked")
    public static Map<String, Object> toMap(String json) {
        return (Map<String, Object>) JSON.parse(json);
    }
616808
public static Map<?, ?> parseJson(String body) {
        JSONReader jr = new JSONValidatingReader();
        Object obj = jr.read(body);
        if (obj instanceof Map<?, ?>) {
            return (Map<?, ?>) obj;
        } else {
            return null;
        }
    }
292273
public Map<String, T> parseMap(JsonParser jsonParser) throws IOException {
        HashMap<String, T> map = new HashMap<String, T>();
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String key = jsonParser.getText();
            jsonParser.nextToken();
            if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
                map.put(key, null);
            } else{
                map.put(key, parse(jsonParser));
            }
        }
        return map;
    }