当前位置: 首页>>代码示例>>Java>>正文


Java Genson类代码示例

本文整理汇总了Java中com.owlike.genson.Genson的典型用法代码示例。如果您正苦于以下问题:Java Genson类的具体用法?Java Genson怎么用?Java Genson使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Genson类属于com.owlike.genson包,在下文中一共展示了Genson类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import com.owlike.genson.Genson; //导入依赖的package包/类
public static final Genson create(boolean pretty) {
	GensonBuilder builder = new GensonBuilder();

	// Install MongoDB / BSON serializers
	tryToAddSerializers("io.datatree.dom.adapters.JsonGensonBsonSerializers", builder);

	// Install serializers for Apache Cassandra
	addSerializer(builder, InetAddress.class, (value, writer, ctx) -> {
		writer.writeString(value.getCanonicalHostName());
	});
	addSerializer(builder, Inet4Address.class, (value, writer, ctx) -> {
		writer.writeString(value.getCanonicalHostName());
	});
	addSerializer(builder, Inet6Address.class, (value, writer, ctx) -> {
		writer.writeString(value.getCanonicalHostName());
	});

	// Set Date format
	builder.useDateAsTimestamp(!Config.USE_TIMESTAMPS);
	if (Config.USE_TIMESTAMPS) {
		builder.useDateFormat(new SimpleDateFormat(Config.TIMESTAMP_FORMAT));
	}
	builder.useIndentation(pretty);
	return builder.create();
}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:26,代码来源:JsonGenson.java

示例2: testSerialization

import com.owlike.genson.Genson; //导入依赖的package包/类
@Test
public void testSerialization() throws TransformationException, IOException {
    int count = rand.nextInt(20)+1;
    HashMap<String, Double> map = new HashMap<>();
    String key = "key";
    for(int i=0;i<count;i++) {
        map.put(key+i, rand.nextDouble());
    }
    
    MultiPoint pointA = new MultiPoint();
    pointA.setValues(map);
    
    Genson genson = new Genson();
    String json = genson.serialize(pointA);
    MultiPoint pointB = genson.deserialize(json, MultiPoint.class);
    Assert.assertEquals(pointA, pointB);
}
 
开发者ID:project-asap,项目名称:IReS-Platform,代码行数:18,代码来源:MultiPointTest.java

示例3: doInBackground

import com.owlike.genson.Genson; //导入依赖的package包/类
@Override
protected Boolean doInBackground(String... params) 
{
	String first = params[0];
	String last = params[1];
	
	Person person = new Person( first, last );
	HttpClient httpClient = new DefaultHttpClient();

	try
	{
		HttpPost post = new HttpPost("http://" + HOST + ":8080/fhws/api/persons" );
		post.setHeader("Content-type", "application/json");
		Genson genson = new Genson();
		post.setEntity( new StringEntity(genson.serialize(person).toString()));
		HttpResponse response = httpClient.execute(post);
		int status = response.getStatusLine().getStatusCode();
		return status == HttpStatus.SC_CREATED;
	}
	catch( Exception e )
	{
		e.printStackTrace();
	}
	
	return false;
}
 
开发者ID:DerGary,项目名称:FHWS-MobileApplikationen,代码行数:27,代码来源:MainActivity.java

示例4: convertFtoC

import com.owlike.genson.Genson; //导入依赖的package包/类
/**
 * http://localhost:8080/v1/api/ftocservice
 * @return
 */
@SuppressWarnings("serial")
@GET
@Produces("application/json")
public Response convertFtoC() {
	Genson genson = new Genson();
	Map<String, Object> jsonObject = new HashMap<String, Object>() {{
		
		Double fahrenheit = 98.24;
		Double celsius;
		celsius = (fahrenheit - 32) * 5 / 9;
		
		Student student = new Student(1,"Genson");
		
		put("F Value", fahrenheit);
		put("C Value", celsius);
		put("student", student);
	}};

	return Response.status(200).entity(genson.serialize(jsonObject)).build();
}
 
开发者ID:ameizi,项目名称:jersey2-restfull-examples,代码行数:25,代码来源:FtoCService.java

示例5: convertFtoCfromInput

import com.owlike.genson.Genson; //导入依赖的package包/类
/**
 * http://localhost:8080/v1/api/ftocservice/9.5
 * @param f
 * @return
 */
@SuppressWarnings("serial")
@Path("{f}")
@GET
@Produces("application/json")
public Response convertFtoCfromInput(@PathParam("f") final float f) {
	Genson genson = new Genson();
	Map<String, Float> jsonObject = new HashMap<String, Float>() {{
		float celsius;
		celsius = (f - 32) * 5 / 9;
		put("F Value", f);
		put("C Value", celsius);
	}};
	
	return Response.status(200).entity(genson.serialize(jsonObject)).build();
}
 
开发者ID:ameizi,项目名称:jersey2-restfull-examples,代码行数:21,代码来源:FtoCService.java

示例6: testLocateGensonContextResolver

import com.owlike.genson.Genson; //导入依赖的package包/类
@Test
public void testLocateGensonContextResolver() {
    Providers providers = instance(Providers.class);

    RuntimeDelegate.setInstance(new DefaultRuntimeDelegate());

    ContextResolver contextResolver = providers.getContextResolver(Genson.class, MediaType.APPLICATION_JSON_TYPE);

    assertNotNull(contextResolver);
    assertEquals(TestGensonContextResolver3.class, contextResolver.getClass());
}
 
开发者ID:geetools,项目名称:geeMVC-Java-MVC-Framework,代码行数:12,代码来源:JaxRsResolverTest.java

示例7: provideBeanPropertyAccessors

import com.owlike.genson.Genson; //导入依赖的package包/类
@Override
public void provideBeanPropertyAccessors(Type ofType, Map<String, LinkedList<PropertyAccessor>> accessorsMap,
    Genson genson) {
    for (Class<?> clazz = getImplementationClass(getRawClass(ofType)); clazz != null
        && !Object.class.equals(clazz); clazz = clazz.getSuperclass()) {
        // first lookup for fields
        if (useFields)
            provideFieldAccessors(clazz, accessorsMap, ofType, genson);
        // and now search methods (getters)
        if (useGettersAndSetters)
            provideMethodAccessors(clazz, accessorsMap, ofType, genson);
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:14,代码来源:DefaultBeanDescriptorProvider.java

示例8: provideBeanPropertyMutators

import com.owlike.genson.Genson; //导入依赖的package包/类
@Override
public void provideBeanPropertyMutators(Type ofType, Map<String, LinkedList<PropertyMutator>> mutatorsMap,
    Genson genson) {
    for (Class<?> clazz = getImplementationClass(getRawClass(ofType)); clazz != null
        && !Object.class.equals(clazz); clazz = clazz.getSuperclass()) {
        // first lookup for fields
        if (useFields)
            provideFieldMutators(clazz, mutatorsMap, ofType, genson);
        // and now search methods (getters)
        if (useGettersAndSetters)
            provideMethodMutators(clazz, mutatorsMap, ofType, genson);
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:14,代码来源:DefaultBeanDescriptorProvider.java

示例9: toString

import com.owlike.genson.Genson; //导入依赖的package包/类
@Override
public String toString() {
    Genson genson = new Genson();
    try {
        return genson.serialize(this);
    } catch (TransformationException | IOException ex) {
        Logger.getLogger(ApplicationInfo.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
 
开发者ID:project-asap,项目名称:IReS-Platform,代码行数:11,代码来源:ApplicationInfo.java

示例10: doInBackground

import com.owlike.genson.Genson; //导入依赖的package包/类
@Override
protected DataAdapter doInBackground(Void... params) 
{
	HttpClient client = new DefaultHttpClient();
	HttpGet get = new HttpGet( "http://" + HOST + ":8080/fhws/api/persons" );
	get.addHeader("Accept", "application/json" );
	DataAdapter adapter = new DataAdapter(ShowPersons.this);
	
	try
	{
		Genson genson = new Genson();
		HttpResponse response = client.execute(get);
		String reply = IOUtils.toString(response.getEntity().getContent());
		Collection<Person> cp = genson.deserialize(reply, new GenericType<List<Person>>(){} );

		for( Person p : cp )
		{
			adapter.addData(p);
		}
	}
	catch( Exception e )
	{
		e.printStackTrace();
	}
	
	return adapter;
}
 
开发者ID:DerGary,项目名称:FHWS-MobileApplikationen,代码行数:28,代码来源:ShowPersons.java

示例11: createModel

import com.owlike.genson.Genson; //导入依赖的package包/类
/**
 * Create a new Model.
 * @param model {@link MLModelData} object
 * @return JSON of {@link MLModelData} object
 */
@POST
@Produces("application/json")
@Consumes("application/json")
public Response createModel(MLModelData model) {
    if (model.getAnalysisId() == 0 || model.getVersionSetId() == 0) {
        logger.error("Required parameters missing");
        return Response.status(Response.Status.BAD_REQUEST).entity("Required parameters missing").build();
    }
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    try {
        int tenantId = carbonContext.getTenantId();
        String userName = carbonContext.getUsername();
        model.setTenantId(tenantId);
        model.setUserName(userName);
        MLModelData insertedModel = mlModelHandler.createModel(model);

        //hide null json fields in response
        String[] fieldsToHide = { MLConstants.ML_MODEL_DATA_ID, MLConstants.ML_MODEL_DATA_CREATED_TIME,
                MLConstants.ML_MODEL_DATA_DATASET_VERSION, MLConstants.ML_MODEL_DATA_ERROR,
                MLConstants.ML_MODEL_DATA_MODEL_SUMMARY };
        Genson.Builder builder = new Genson.Builder();
        for (int i = 0; i < fieldsToHide.length; i++) {
            builder = builder.exclude(fieldsToHide[i], MLModelData.class);
        }
        Genson genson = builder.create();
        String insertedModelJson = genson.serialize(insertedModel);
        return Response.ok(insertedModelJson).build();
    } catch (MLModelHandlerException e) {
        String msg = MLUtils.getErrorMsg("Error occurred while creating a model : " + model, e);
        logger.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
                .build();
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-ml,代码行数:40,代码来源:ModelApiV20.java

示例12: init

import com.owlike.genson.Genson; //导入依赖的package包/类
@Override
public void init(Map<String, String> config) {
    JsonProvider provider = new GensonJsonProvider();
    
    parserFactory = provider.createParserFactory(config);
    readerFactory = provider.createReaderFactory(config);
    generatorFactory = provider.createGeneratorFactory(config);
    genson = new Genson();
}
 
开发者ID:salyh,项目名称:jsr353-benchmark,代码行数:10,代码来源:GensonParser.java

示例13: create

import com.owlike.genson.Genson; //导入依赖的package包/类
@Override
public Converter create(BeanProperty property, Genson genson) {
    if (property.getRawClass().isAssignableFrom(IdRef.class)) {
        return IdRefConverters.idRefConverter;
    }
    if (property.getRawClass().isAssignableFrom(LazyJson.class)) {
        return LazyJsonConverters.get(property.getName(), property.getType());
    }
    return null;
}
 
开发者ID:feroult,项目名称:yawp,代码行数:11,代码来源:CustomContextualFactory.java

示例14: genson

import com.owlike.genson.Genson; //导入依赖的package包/类
@Override
public Genson genson() {
    return genson;
}
 
开发者ID:fabienrenaud,项目名称:java-json-benchmark,代码行数:5,代码来源:UsersJsonProvider.java

示例15: getContext

import com.owlike.genson.Genson; //导入依赖的package包/类
@Override
public Genson getContext(Class<?> type) {
    return new Genson();
}
 
开发者ID:geetools,项目名称:geeMVC-Java-MVC-Framework,代码行数:5,代码来源:TestGensonContextResolver3.java


注:本文中的com.owlike.genson.Genson类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。