本文整理汇总了Java中com.fasterxml.jackson.datatype.joda.JodaModule类的典型用法代码示例。如果您正苦于以下问题:Java JodaModule类的具体用法?Java JodaModule怎么用?Java JodaModule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JodaModule类属于com.fasterxml.jackson.datatype.joda包,在下文中一共展示了JodaModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObjectMapper
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的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: SiloTemplateResolver
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的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;
}
示例3: testUpdatePost
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
@Test
public void testUpdatePost() throws Exception {
Post post = posts.get(0);
post.setTitle("New Title");
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JodaModule());
String json = objectMapper.writeValueAsString(post);
mockMvc.perform(
put(PATH + "/{uuid}", post.getUuid())
.content(json)
.contentType(MediaType.APPLICATION_JSON)
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.title", is("New Title")));
assertThat(postRepository.findOne(post.getUuid()).getTitle(), is("New Title"));
}
示例4: getInstance
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
public static JGMRConfig getInstance() {
if (instance == null) {
File configFile = new File("jGMR.config");
try {
if (configFile.exists()) {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
instance = mapper.readValue(configFile, JGMRConfig.class);
} else {
instance = new JGMRConfig();
instance.notificationsMinized = true;
instance.minimizeToTray = true;
instance.saveFileDialog = true;
instance.logToFile = false;
instance.dontAskMeToSave = false;
instance.notificationFrequency = 15;
}
} catch (Exception ex) {
Logger.getLogger(JGMRConfig.class.getName()).log(Level.SEVERE, null, ex);
}
}
return instance;
}
示例5: JiraService
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
public JiraService(final Site jiraSite) {
this.jiraSite = jiraSite;
final ConnectionPool CONNECTION_POOL = new ConnectionPool(5, 60, TimeUnit.SECONDS);
OkHttpClient httpClient = new OkHttpClient.Builder()
.connectTimeout(jiraSite.getTimeout(), TimeUnit.MILLISECONDS)
.readTimeout(10000, TimeUnit.MILLISECONDS).connectionPool(CONNECTION_POOL)
.retryOnConnectionFailure(true).addInterceptor(new SigningInterceptor(jiraSite)).build();
final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
this.jiraEndPoints = new Retrofit.Builder().baseUrl(this.jiraSite.getUrl().toString())
.addConverterFactory(JacksonConverterFactory.create(mapper))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()).client(httpClient).build()
.create(JiraEndPoints.class);
}
示例6: testModalTypeSerialization
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
@Test
public void testModalTypeSerialization() {
String expected = "{\"type\":\"IndividualTrip\",\"uuid\":null,\"start\":null,\"end\":null,\"status\":null," +
"\"lengthInM\":0.0,\"messageList\":null,\"modalType\":\"walk\",\"isAccessible\":null," +
"\"ticketMatches\":null,\"pathDataSource\":null,\"pathData\":null,\"durationInS\":null}";
IndividualTrip trip = new IndividualTrip.Builder().withModalType(ModalType.walk).build();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
mapper.addMixInAnnotations(IndividualTrip.class, UraIndividualTripMixIn.class);
Writer stringWriter = new StringWriter();
try {
mapper.writeValue(stringWriter, trip);
String json = stringWriter.toString();
assertNotNull(json);
assertEquals(json, expected);
} catch (Exception e) {
fail();
}
}
示例7: newInstance
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
/**
* Creates properly configured Jackson XML Mapper instances.
* @return XmlMapper instance.
*/
public static XmlMapper newInstance() {
// Create new mapper
final JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper mapper = new XmlMapper(module);
// Configure it
mapper
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
.registerModule(new JodaModule())
.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
return mapper;
}
示例8: readParamsFile
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
private OnlineProcessParameters readParamsFile(String filename, PrintStream out)
throws JsonParseException, JsonMappingException, IOException {
Path procFile = Paths.get(filename);
if (Files.exists(procFile)) {
InputStream is = new FileInputStream(procFile.toFile());
String json = IOUtils.toString(is);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JodaModule());
objectMapper.configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
false);
return objectMapper.readValue(json, OnlineProcessParameters.class);
} else {
out.println("File not found: " + filename);
}
return null;
}
示例9: DiscoveryApi
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
public DiscoveryApi(String apiKey, DiscoveryApiConfiguration configuration) {
Preconditions.checkNotNull(apiKey, "The API key is mandatory");
this.apiKey = apiKey;
this.configuration = configuration;
this.mapper = new ObjectMapper() //
.registerModule(new JodaModule()) //
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.client = new OkHttpClient.Builder()
.readTimeout(configuration.getSocketTimeout(), TimeUnit.MILLISECONDS)
.connectTimeout(configuration.getSocketConnectTimeout(), TimeUnit.MILLISECONDS)
.build();
this.pathByType = new HashMap<>();
this.pathByType.put(Event.class, "events");
this.pathByType.put(Attraction.class, "attractions");
this.pathByType.put(Venue.class, "venues");
this.apiKeyQueryParam=configuration.getApiKeyQueryParam();
}
示例10: writeObject
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
/**
* Writes an object and its properties recursively to the console. Properties are automatically indented.
*
* @param object The object to print to the console.
* @param title An optional title to display.
* @param indent The starting indentation.
*/
public void writeObject( Object object, String title )
{
ObjectMapper mapper =
new ObjectMapper().configure( SerializationFeature.INDENT_OUTPUT, true ).registerModule( new JodaModule() );
;
System.out.println();
System.out.println( title );
System.out.println( new String( new char[90] ).replace( '\0', '-' ) );
try
{
System.out.println( mapper.writeValueAsString( object ) );
}
catch ( JsonProcessingException e )
{
throw new RuntimeException( e );
}
}
示例11: initMapper
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
/**
* Initializes an object mapper.
*
* @param mapper the mapper to initialize
* @return the initialized mapper
*/
private static ObjectMapper initMapper(ObjectMapper mapper) {
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true)
.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.registerModule(new JodaModule())
.registerModule(ByteArraySerializer.getModule())
.registerModule(Base64UrlSerializer.getModule())
.registerModule(DateTimeSerializer.getModule())
.registerModule(DateTimeRfc1123Serializer.getModule())
.registerModule(HeadersSerializer.getModule());
mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
return mapper;
}
示例12: initializeObjectMapper
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
/**
* Initializes an instance of JacksonMapperAdapter with default configurations
* applied to the object mapper.
*
* @param mapper the object mapper to use.
*/
private static ObjectMapper initializeObjectMapper(ObjectMapper mapper) {
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true)
.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.registerModule(new JodaModule())
.registerModule(ByteArraySerializer.getModule())
.registerModule(Base64UrlSerializer.getModule())
.registerModule(DateTimeSerializer.getModule())
.registerModule(DateTimeRfc1123Serializer.getModule())
.registerModule(HeadersSerializer.getModule());
mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
return mapper;
}
示例13: buildWebServices
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
/**
* Build the web services to use and assign them to the application state.
*/
protected void buildWebServices() {
// Build an ObjectMapper for everyone to use, since they are heavy-weight
ObjectMapper mapper = new ObjectMapper();
JodaModule jodaModule = new JodaModule();
jodaModule.addSerializer(Interval.class, new ToStringSerializer());
mapper.registerModule(jodaModule);
// This alternate switched implementation approach is not really used anywhere, should be split off into a
// separate subclass if needed
if (state.webService == null) {
state.webService = useTestWebService ?
new TestDruidWebService("Test UI WS") :
new AsyncDruidWebServiceImpl(DruidClientConfigHelper.getServiceConfig(), mapper);
}
if (state.metadataWebService == null) {
state.metadataWebService = (useTestWebService) ?
new TestDruidWebService("Test Metadata WS") :
new AsyncDruidWebServiceImpl(DruidClientConfigHelper.getMetadataServiceConfig(), mapper);
}
}
示例14: init
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
@Before
public void init() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
reset(financingRoundRepository, financingRoundService);
financingRoundEntities = new ArrayList<>();
fixedDate = DateTime.parse("2015-01-10T10:10:10Z");
financingRoundEntities.add(financingRoundEntity(fixedDate.minusDays(100), fixedDate.minusDays(50)));
financingRoundEntities.add(financingRoundEntity(fixedDate.minusDays(40), fixedDate.minusDays(30)));
when(financingRoundRepository.findAll()).thenReturn(financingRoundEntities);
List<UserEntity> userEntities = new ArrayList<>();
userEntities.add(new UserEntity("[email protected]"));
userEntities.add(new UserEntity("[email protected]"));
mapper.registerModule(new JodaModule());
}
示例15: jacksonJodaModule
import com.fasterxml.jackson.datatype.joda.JodaModule; //导入依赖的package包/类
@Bean
public JodaModule jacksonJodaModule() {
JodaModule module = new JodaModule();
module.addSerializer(DateTime.class, new CustomDateTimeSerializer());
module.addDeserializer(DateTime.class, new CustomDateTimeDeserializer());
module.addSerializer(LocalDate.class, new CustomLocalDateSerializer());
module.addDeserializer(LocalDate.class, new ISO8601LocalDateDeserializer());
return module;
}