本文整理汇总了Java中com.fasterxml.jackson.datatype.guava.GuavaModule类的典型用法代码示例。如果您正苦于以下问题:Java GuavaModule类的具体用法?Java GuavaModule怎么用?Java GuavaModule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GuavaModule类属于com.fasterxml.jackson.datatype.guava包,在下文中一共展示了GuavaModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObjectMapper
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
@Bean(name = "objectMapper")
public ObjectMapper getObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new GuavaModule());
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JodaModule());
mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
// borrowed from: http://jackson-users.ning.com/forum/topics/how-to-not-include-type-info-during-serialization-with
@Override
protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config, Annotated ann, JavaType baseType) {
// Don't serialize JsonTypeInfo Property includes
if (ann.hasAnnotation(JsonTypeInfo.class)
&& ann.getAnnotation(JsonTypeInfo.class).include() == JsonTypeInfo.As.PROPERTY
&& SerializationConfig.class.isAssignableFrom(config.getClass())) {
return null;
}
return super._findTypeResolver(config, ann, baseType);
}
});
return mapper;
}
示例2: roundtrip
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
@Test
public void roundtrip() throws IOException {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enableDefaultTyping();
objectMapper.registerModule(new GuavaModule());
ImmutableOuterObject outer = ImmutableOuterObject.builder()
.emptyObject(
ImmutableEmptyObject
.builder()
.build())
.build();
String serialized = objectMapper.writeValueAsString(outer);
check(objectMapper.readValue(serialized, ImmutableOuterObject.class)).is(outer);
}
示例3: SiloTemplateResolver
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
public SiloTemplateResolver(Class<T> classType) {
ObjectMapper m = new ObjectMapper();
m.registerModule(new GuavaModule());
m.registerModule(new LogbackModule());
m.registerModule(new GuavaExtrasModule());
m.registerModule(new JodaModule());
m.registerModule(new JSR310Module());
m.registerModule(new AfterburnerModule());
m.registerModule(new FuzzyEnumModule());
m.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
m.setSubtypeResolver(new DiscoverableSubtypeResolver());
//Setup object mapper to ignore the null properties when serializing the objects
m.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//Lets be nice and allow additional properties by default. Allows for more flexible forward/backward
//compatibility and works well with jackson addtional properties feature for serialization
m.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
this.classType = classType;
this.mapper = m;
}
示例4: beforeAll
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
@Before
public void beforeAll() throws Exception {
server = new TestingServer();
server.start();
Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
when(mockCapabilities.supportsNamedVips()).thenReturn(true);
taskFactory = new CassandraDaemonTask.Factory(mockCapabilities);
configurationFactory = new ConfigurationFactory<>(
MutableSchedulerConfiguration.class,
BaseValidator.newValidator(),
Jackson.newObjectMapper()
.registerModule(new GuavaModule())
.registerModule(new Jdk8Module()),
"dw");
connectString = server.getConnectString();
}
示例5: createPokemonIndex
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
public static void createPokemonIndex() throws IOException {
Map<String, Team> teams = readTeamsFromFile();
Map<String, List<String>> index = new HashMap<>();
for (String pokemon : PokemonListingCache.getAll().keySet()) {
index.put(pokemon, new ArrayList<>());
}
for (Team t : teams.values()) {
index.get(t.getP1()).add(t.getId());
index.get(t.getP2()).add(t.getId());
index.get(t.getP3()).add(t.getId());
}
ObjectMapper om = new ObjectMapper();
om.registerModule(new GuavaModule());
File indexDir = new File("output/indexes");
if (!indexDir.exists()) indexDir.mkdir();
om.writeValue(new File(indexDir, "pk-team-index.json"), index);
}
示例6: DataGenerationDriver
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
public DataGenerationDriver(Set<String> pokemonToAnalyze, Arguments args) throws IOException {
this.pokemonSet = pokemonToAnalyze;
this.setSize = args.setSize;
this.numberOfBattlesPerTeam = args.numberOfBattlesPerTeam;
this.skipExistingFiles = args.skipExistingFiles;
if (!outputDirectory.exists()) {
outputDirectory.mkdir();
}
File teamFile = new File(outputDirectory, "teams.json");
if (teamFile.exists()) {
ObjectMapper om = new ObjectMapper();
om.registerModule(new GuavaModule());
JavaType teamType = om.getTypeFactory().constructMapType(HashMap.class, String.class, Team.class);
generatedData.addAllTeams(om.readValue(teamFile, teamType));
} else {
buildTeams();
}
simulateBattleTrees();
}
示例7: getObjectMapper
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
@Produces
@Omakase
public ObjectMapper getObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
ImmutableSet<SimpleModule> modules = getModules();
if (getModules() != null) {
modules.stream().forEach(mapper::registerModule);
}
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.registerModule(new GuavaModule());
return mapper;
}
示例8: getObjectMapper
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
public ObjectMapper getObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
ImmutableSet<SimpleModule> modules = getModules();
if (getModules() != null) {
modules.stream().forEach(mapper::registerModule);
}
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.registerModule(new GuavaModule());
return mapper;
}
示例9: config
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
/**
* Load plugin config with Guava & Joda support
*/
private static ConfigSource config()
{
String path = System.getenv("EMBULK_OUTPUT_MAILCHIMP_TEST_CONFIG");
assumeThat(isNullOrEmpty(path), is(false));
try {
ObjectMapper mapper = new ObjectMapper()
.registerModule(new GuavaModule())
.registerModule(new JodaModule());
ConfigLoader configLoader = new ConfigLoader(new ModelManager(null, mapper));
return configLoader.fromYamlFile(new File(path));
}
catch (IOException ex) {
throw Throwables.propagate(ex);
}
}
示例10: should_jongo_map_key
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
@Test
public void should_jongo_map_key() throws Exception {
// ObjectMapper frontObjectMapper = FACTORY.getComponent(Name.of(ObjectMapper.class, "FrontObjectMapper"));
ObjectMapper frontObjectMapper = new ObjectMapper()
.registerModule(new JodaModule())
.registerModule(new GuavaModule())
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
String json = "{\"@class\":\"com.vino.backend.model.Movement\",\"_id\":\"53581a4f036419598a363d94\"," +
"\"type\":\"OUT\",\"amount\":1,\"record\":" +
"{\"@class\":\"com.vino.model.WineCellarRecord\",\"_id\":\"53581a4f036419598a363d94\",\"" +
"domain\":\"5323918203647408e5a3ec3d\",\"vintage\":12,\"quantity\":20}}";
Movement movement = frontObjectMapper.readValue(json, Movement.class);
assertThat(movement.getKey()).isNotNull();
assertThat(movement.getRecord()).isNotNull();
assertThat(movement.getRecord().getKey()).isNotNull().isNotEmpty();
}
示例11: create
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
public static ObjectMapper create(Module... extraModules) {
SimpleModule module = new SimpleModule();
module.addSerializer(boolean.class, new BooleanSerializer(Boolean.class));
module.addSerializer(Enum.class, new EnumSerializer(Enum.class));
module.setDeserializerModifier(new EnumDeserializerModifier());
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
mapper.registerModule(new GuavaModule());
for (Module extraModule : extraModules) {
mapper.registerModule(extraModule);
}
mapper.setSerializationInclusion(Include.NON_ABSENT);
return mapper;
}
示例12: convert
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
@Test
public void convert() throws JsonParseException, JsonMappingException,
JsonProcessingException, IOException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new GuavaModule());
Multimap<String, NavItem> navs = objectMapper.readValue(
objectMapper.treeAsTokens(objectMapper.readTree(jsonString)),
objectMapper.getTypeFactory().constructMapLikeType(
Multimap.class, String.class, NavItem.class));
logger.info(navs);
assertThat(navs.keys(), hasItems("123455", "999999"));
}
示例13: testAggregateCounts
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
@Test(enabled = false, description = "Needs REMOTE constants")
public void testAggregateCounts() throws Exception {
String tenant = "999";
MiruTenantId tenantId = new MiruTenantId(tenant.getBytes(Charsets.UTF_8));
HttpClientFactory httpClientFactory = new HttpClientFactoryProvider()
.createHttpClientFactory(Collections.<HttpClientConfiguration>emptyList(), false);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new GuavaModule());
HttpRequestHelper requestHelper = new HttpRequestHelper(httpClientFactory.createClient(null, REMOTE_HOST, REMOTE_PORT), objectMapper);
int queries = 100;
for (int i = 0; i < queries; i++) {
query(requestHelper, tenantId);
}
}
示例14: configureMapper
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
/**
* <p>configureMapper.</p>
*
* @param mapper a {@link com.fasterxml.jackson.databind.ObjectMapper} object.
* @param mode App mode
*/
public static void configureMapper(ObjectMapper mapper, Application.Mode mode) {
mapper.registerModule(new GuavaModule());
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX)
.enable(MapperFeature.PROPAGATE_TRANSIENT_MARKER)
.disable(
SerializationFeature.WRITE_NULL_MAP_VALUES,
SerializationFeature.FAIL_ON_EMPTY_BEANS
);
if (!mode.isDev()) {
mapper.disable(
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
);
}
}
示例15: newXMLMapper
import com.fasterxml.jackson.datatype.guava.GuavaModule; //导入依赖的package包/类
/**
* Creates a new {@link com.fasterxml.jackson.dataformat.xml.XmlMapper} using Woodstox
* with Logback and Joda Time support.
* Also includes all {@link io.dropwizard.jackson.Discoverable} interface implementations.
*
* @return XmlMapper
*/
public static XmlMapper newXMLMapper(JacksonXmlModule jacksonXmlModule) {
final XmlFactory woodstoxFactory = new XmlFactory(new WstxInputFactory(), new WstxOutputFactory());
final XmlMapper mapper = new XmlMapper(woodstoxFactory, jacksonXmlModule);
mapper.registerModule(new GuavaModule());
mapper.registerModule(new LogbackModule());
mapper.registerModule(new GuavaExtrasModule());
mapper.registerModule(new JodaModule());
mapper.registerModule(new FuzzyEnumModule());
mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
return mapper;
}