@JsonSerializer spring specific field string to date
Java
@Configuration
public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {
private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
@Value("${spring.data.elasticsearch.host}")
private String elasticSearchHost;
@Value("${spring.data.elasticsearch.port}")
private String elasticSearchPort;
@Bean
public RestHighLevelClient elasticsearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(elasticSearchHost + ":" + elasticSearchPort)
.usingSsl()
.build();
return RestClients.create(clientConfiguration).rest();
}
@Bean
public EntityMapper entityMapper() {
ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(elasticsearchMappingContext(), new DefaultConversionService());
entityMapper.setConversions(elasticsearchCustomConversions());
return entityMapper;
}
@Override
public ElasticsearchCustomConversions elasticsearchCustomConversions() {
return new ElasticsearchCustomConversions(Arrays.asList(DateToStringConverter.INSTANCE, StringToDateConverter.INSTANCE));
}
@WritingConverter
enum DateToStringConverter implements Converter<Date, String> {
INSTANCE;
@Override
public String convert(Date date) {
return formatter.format(date);
}
}
@ReadingConverter
enum StringToDateConverter implements Converter<String, Date> {
INSTANCE;
@Override
public Date convert(String s) {
try {
return formatter.parse(s);
} catch (ParseException e) {
return null;
}
}
}
}
Also in Java:
- Title
- android image view showing rotate image
- Category
- Java
- Title
- java while loop break
- Category
- Java
- Title
- rgb to hex java
- Category
- Java
- Title
- how to make an arraylist java
- Category
- Java
- Title
- java string to char array
- Category
- Java
- Title
- tostring() java example
- Category
- Java
- Title
- android foreground push notification
- Category
- Java
- Title
- arraylist remove method java
- Category
- Java
- Title
- write an infinite loop java
- Category
- Java
- Title
- java switch display panel
- Category
- Java
- Title
- how to declare an array in java
- Category
- Java
- Title
- java copy array
- Category
- Java
- Title
- enhanced for loop java
- Category
- Java
- Title
- how to send http post create request using curl command
- Category
- Java
- Title
- check java version cmd
- Category
- Java
- Title
- java foreach map
- Category
- Java
- Title
- arraylist with values java
- Category
- Java
- Title
- how to iterate hashset in java 8
- Category
- Java
- Title
- override java
- Category
- Java
- Title
- how to get individual words from a string in java
- Category
- Java
- Title
- spigot action bar
- Category
- Java
- Title
- write an object java in a file
- Category
- Java
- Title
- how to print in java
- Category
- Java
- Title
- reverse shuffle merge
- Category
- Java
- Title
- javafx datepicker
- Category
- Java
- Title
- java how to read file extension
- Category
- Java
- Title
- java create unmodifiable list
- Category
- Java
- Title
- how to find complement of a number in java
- Category
- Java
- Title
- import java.io.serializable
- Category
- Java
- Title
- sdkmanager JAVA_HOME invalid directory
- Category
- Java
- Title
- java script find screen size of device
- Category
- Java
- Title
- Java If statemtn
- Category
- Java
- Title
- java jpa criteriabuilder in xample
- Category
- Java
- Title
- array null pointer java
- Category
- Java
- Title
- java file class
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- 3-way radix quicksort java
- Category
- Java
- Title
- listview get selected java
- Category
- Java
- Title
- java remove first character from string
- Category
- Java
- Title
- how to copy list item to another list in java
- Category
- Java
- Title
- java classes and methods
- Category
- Java
- Title
- two dimensional array in java example program
- Category
- Java
- Title
- java null pointer exception
- Category
- Java
- Title
- how to format a datetime object to show date and time and milliseconds in java
- Category
- Java
- Title
- integer max value java
- Category
- Java
- Title
- try block in java
- Category
- Java
- Title
- java list as parameter
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java
- Title
- take a peice from array java
- Category
- Java
- Title
- how to do substring java
- Category
- Java
- Title
- connect 2 package in android
- Category
- Java
- Title
- binary number input in int java
- Category
- Java
- Title
- count the number of words in a string java
- Category
- Java
- Title
- how to count the number of occurrences of an element in a arraylist in java
- Category
- Java
- Title
- how to create array of linkedlist in java
- Category
- Java
- Title
- java save string in text file
- Category
- Java
- Title
- java 8 add whole array to jsonarray
- Category
- Java
- Title
- java break in foreach
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- Java system load from resources
- Category
- Java
- Title
- java new string with values
- Category
- Java
- Title
- java arraylist
- Category
- Java
- Title
- bootstrap center text vertically
- Category
- Java
- Title
- excel data formatter in java
- Category
- Java
- Title
- java script to detect the crome browser
- Category
- Java
- Title
- how to create a circle in java
- Category
- Java
- Title
- how to get elements of a list in java
- Category
- Java
- Title
- how to check if a string is in alphabetical order in java
- Category
- Java
- Title
- java read each lines in file
- Category
- Java
- Title
- how add strings together
- Category
- Java
- Title
- counting the sequence of character in string java
- Category
- Java
- Title
- java length of matrix
- Category
- Java
- Title
- spigot get player from UUID
- Category
- Java
- Title
- java observable to observer stack overflow
- Category
- Java
- Title
- java count substring occurrences in string
- Category
- Java
- Title
- how to see if a shape is touching another shape in java
- Category
- Java
- Title
- java stream collect to string
- Category
- Java
- Title
- Java how to handle HTTP GET request after establishing TCP connection
- Category
- Java
- Title
- java previous permutation
- Category
- Java
- Title
- main class java
- Category
- Java
- Title
- java treemap
- Category
- Java
- Title
- insert element into arraylist java
- Category
- Java
- Title
- int to binary string java
- Category
- Java
- Title
- converter int array para string java
- Category
- Java
- Title
- java string format .2f
- Category
- Java
- Title
- in java how to compare two strings
- Category
- Java
- Title
- java resultset to table
- Category
- Java
- Title
- add video in bootstrap
- Category
- Java
- Title
- int java
- Category
- Java
- Title
- The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the `--no-shrink` flag to this command.
- Category
- Java
- Title
- android java retrofit offline cache
- Category
- Java
- Title
- remove space string java
- Category
- Java
- Title
- reading in lines from a file java
- Category
- Java
- Title
- how to add a number to an array in java
- Category
- Java
- Title
- java get icon for file type
- Category
- Java
- Title
- loop through java object
- Category
- Java
- Title
- how to exit a java program
- Category
- Java
- Title
- how to take binary input in java
- Category
- Java
- Title
- how to check how many anagrams a word has in java
- Category
- Java
- Title
- pascal's triangle java 2d array
- Category
- Java