Create data model definition from JSON file.
@param resource resource with JSON definition
@return created data model
@throws RuntimeException when definition is incorrect or there is a i/o problem with stream
191054
public final DataModel fromJson(final InputStream resource) {
		ObjectMapper mapper = new ObjectMapper();
		mapper
			.addMixInAnnotations(DataType.class, DataTypeConfigMixin.class);
		mapper
			.addMixInAnnotations(ObjectDataType.class, ObjectDataTypeConfigMixin.class);
		try {
			return mapper.readValue(resource, DataModel.class);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
505927
def build_json_resource_obj(cls, fields, resource, resource_instance, resource_name,
                                force_type_resolution=False):
        
        # Determine type from the instance if the underlying model is polymorphic
        if force_type_resolution:
            resource_name = utils.get_resource_type_from_instance(resource_instance)
        resource_data = [
            ('type', resource_name),
            ('id', encoding.force_text(resource_instance.pk) if resource_instance else None),
            ('attributes', cls.extract_attributes(fields, resource)),
        ]
        relationships = cls.extract_relationships(fields, resource, resource_instance)
        if relationships:
            resource_data.append(('relationships', relationships))
        # Add 'self' link if field is present and valid
        if api_settings.URL_FIELD_NAME in resource and \
                isinstance(fields[api_settings.URL_FIELD_NAME], relations.RelatedField):
            resource_data.append(('links', {'self': resource[api_settings.URL_FIELD_NAME]}))
        return OrderedDict(resource_data)
1267865
public static File getResourceAsFile(String resource) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        try {
            return new File(URLDecoder.decode(cl.getResource(resource)
                    .getFile(), "UTF-8"));
        } catch (UnsupportedEncodingException uee) {
            return null;
        }
    }
756502
protected GsonJsonEngine createGsonJsonEngine(JsonEngineResource resource) {
        final boolean serializeNulls = isGsonSerializeNulls();
        final boolean prettyPrinting = isGsonPrettyPrinting();
        final Consumer<GsonBuilder> builderSetupper = prepareGsonBuilderSetupper(serializeNulls, prettyPrinting);
        final Consumer<JsonMappingOption> optionSetupper = prepareMappingOptionSetupper(resource.getMappingOption());
        return resource.getYourEngineCreator().map(creator -> { // rare option
            return createYourEngine(creator, builderSetupper, optionSetupper);
        }).orElseGet(() -> { // mainly here
            return newGsonJsonEngine(builderSetupper, optionSetupper);
        });
    }
626402
static Resource createResourceFromDomainModelOp(final ModelNode result, final Set<String> extensions) {
        final Resource root = Resource.Factory.create();
        for (ModelNode model : result.asList()) {

            final PathAddress resourceAddress = PathAddress.pathAddress(model.require(DOMAIN_RESOURCE_ADDRESS));

            if (resourceAddress.size() == 1) {
                final PathElement element = resourceAddress.getElement(0);
                if (element.getKey().equals(EXTENSION)) {
                    if (!extensions.contains(element.getValue())) {
                        extensions.add(element.getValue());
                    }
                }
            }

            Resource resource = root;
            final Iterator<PathElement> i = resourceAddress.iterator();
            if (!i.hasNext()) { //Those are root attributes
                resource.getModel().set(model.require(DOMAIN_RESOURCE_MODEL));
            }
            while (i.hasNext()) {
                final PathElement e = i.next();

                if (resource.hasChild(e)) {
                    resource = resource.getChild(e);
                } else {
                    /*
                    {
                        "domain-resource-address" => [
                            ("profile" => "test"),
                            ("subsystem" => "test")
                        ],
                        "domain-resource-model" => {},
                        "domain-resource-properties" => {"ordered-child-types" => ["ordered-child"]}
                    }*/
                    final Resource nr;
                    if (model.hasDefined(DOMAIN_RESOURCE_PROPERTIES, ORDERED_CHILD_TYPES_PROPERTY)) {
                        List<ModelNode> list = model.get(DOMAIN_RESOURCE_PROPERTIES, ORDERED_CHILD_TYPES_PROPERTY).asList();
                        Set<String> orderedChildTypes = new HashSet<String>(list.size());
                        for (ModelNode type : list) {
                            orderedChildTypes.add(type.asString());
                        }
                        nr = Resource.Factory.create(false, orderedChildTypes);
                    } else {
                        nr = Resource.Factory.create();
                    }
                    resource.registerChild(e, nr);
                    resource = nr;
                }

                if (!i.hasNext()) {
                    resource.getModel().set(model.require(DOMAIN_RESOURCE_MODEL));
                }
            }
        }
        return root;
    }
1325673
private DataSource getDataSource(ComponentHelper cmp, Resource resource) {
    try {
      /*
       * by default the path is read from request "path" parameter
       * here we overwrite it via a synthetic resource because the path may be overwritten by validation logic
       * to ensure the path is not beyond the configured root path
       */
      ValueMap overwriteProperties = new ValueMapDecorator(ImmutableMap.<String, Object>of("path", resource.getPath()));
      Resource dataSourceResourceWrapper = GraniteUiSyntheticResource.wrapMerge(request.getResource(), overwriteProperties);
      return cmp.getItemDataSource(dataSourceResourceWrapper);
    }
    catch (ServletException | IOException ex) {
      throw new RuntimeException("Unable to get data source.", ex);
    }
  }
881825
def create(self, resource):
        
        schema = PackageSchema(exclude=('id', 'created', 'updated', 'test_count', 'agent_id', 'result_id'))
        json = self.service.encode(schema, resource)

        schema = PackageSchema()
        resp = self.service.create(self.base, json)
        return self.service.decode(schema, resp)
836893
protected JSON createJSON( Map model, HttpServletRequest request, HttpServletResponse response ) {
      return defaultCreateJSON( model );
   }
520098
public static Schema fromJson(String json) {
        try{
            return JsonMappers.getMapper().readValue(json, Schema.class);
        } catch (Exception e){
            //TODO better exceptions
            throw new RuntimeException(e);
        }
    }
400525
public static IDataSource create(JsonObject config) throws DataSourceCreationException {
        String title = config.getAsJsonPrimitive("title").getAsString();
        String description = config.getAsJsonPrimitive("description").getAsString();
        String typeName = config.getAsJsonPrimitive("type").getAsString();
        
        JsonObject settings = config.getAsJsonObject("settings");

        final IDataSourceType type = DataSourceTypesRegistry.getType(typeName);
        if ( type == null )
            throw new UnknownDataSourceTypeException(typeName);

        return type.createDataSource( title, description, settings );
    }
462513
public static InputStream getResourceAsInputStream(String resource) {
        InputStream in = classLoaderWrapper.getResourceAsStream(resource);
        if (in == null) {
            return null;
        }
        return in;
    }
221324
protected GodHandResource createGodHandResource(ActionRuntime runtime) {
        return new GodHandResource(assistantDirector, timeManager, messageManager, exceptionTranslator, requestManager, responseManager,
                sessionManager, myLoginManager(), apiManager);
    }
882671
def create_resource(resource, opts = {})
      data, _status_code, _headers = create_resource_with_http_info(resource, opts)
      return data
    end
504318
public static Reader getResourceAsReader(String resource) {
        InputStream in = classLoaderWrapper.getResourceAsStream(resource);
        if (in == null) {
            return null;
        }
        return new InputStreamReader(in);
    }
875221
public void write(@NonNull Resource resource) throws IOException {
      try (JsonWriter writer = Json.createWriter(resource)) {
         writer.beginDocument();
         writer.property("id", getId());
         writer.property("content", toString());

         if (attributes.size() > 0) {
            writer.beginObject("attributes");
            for (Map.Entry<AttributeType, Val> entry : attributeEntrySet()) {
               writer.property(entry.getKey().name(), entry.getKey().getValueType().encode(entry.getValue()));
            }
            writer.endObject();
         }

         if (annotationSet.size() > 0) {
            writer.beginObject("completed");
            for (AnnotatableType type : getAnnotationSet().getCompleted()) {
               writer.property(type.canonicalName(), getAnnotationSet().getAnnotationProvider(type));
            }
            writer.endObject();

            writer.beginArray("annotations");
            for (Annotation annotation : annotationSet) {
               writer.beginObject();
               writer.property("type", annotation.getType().name());
               writer.property("start", annotation.start());
               writer.property("end", annotation.end());
               writer.property("id", annotation.getId());
               if (Config.get("Annotation.writeContent").asBooleanValue(false)) {
                  writer.property("content", annotation.toString());
               }

               if (annotation.getAttributeMap().size() > 0) {
                  writer.beginObject("attributes");
                  for (Map.Entry<AttributeType, Val> entry : annotation.attributeEntrySet()) {
                     writer.property(entry.getKey().name(),
                                     entry.getKey().getValueType().encode(entry.getValue()));

                  }
                  writer.endObject();
               }

               Collection<Relation> relations = annotation.relations();
               if (relations.size() > 0) {
                  writer.beginArray("relations");
                  for (Relation relation : relations) {
                     writer.beginObject();
                     writer.property("type", relation.getType());
                     writer.property("value", relation.getValue());
                     writer.property("target", relation.getTarget());
                     writer.endObject();
                  }
                  writer.endArray();
               }

               writer.endObject();
            }
            writer.endArray();
         }
         writer.endDocument();
      }
   }
1183940
static JsonSchema initializeFromSource(final Map<String, Object> source) {

		final Object idValue = source.get(JsonSchema.KEY_ID);
		URI id               = null;

		if (idValue != null) {

			try {

				id = new URI(idValue.toString());

			} catch (URISyntaxException ex) {
				logger.warn("", ex);
			}
		}

		final StructrSchemaDefinition schema = new StructrSchemaDefinition(id);
		schema.deserialize(source);

		return schema;
	}
75327
public Map<String, Object> create(String entityName, String groupId, String jsonStr, MnoHttpClient httpClient) throws AuthenticationException, ApiException, InvalidRequestException {
		String jsonBody = httpClient.post(getCollectionUrl(entityName, groupId), jsonStr);
		Type typeOfHashMap = HashMap.class;
		return GSON.fromJson(jsonBody, typeOfHashMap);
	}