-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
autoconfig-example/src/main/java/no/bouvet/autoconfig/JodaTimeAutoconfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package no.bouvet.autoconfig; | ||
|
||
import com.fasterxml.jackson.databind.Module; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import org.joda.time.LocalDate; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
|
||
@Configuration | ||
@ConditionalOnClass(LocalDate.class) | ||
public class JodaTimeAutoconfig { | ||
@Bean | ||
public Module module() { | ||
SimpleModule module = new SimpleModule(); | ||
module.addSerializer(LocalDate.class, new JodaTimeSerializer()); | ||
return module; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
autoconfig-example/src/main/java/no/bouvet/autoconfig/JodaTimeSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package no.bouvet.autoconfig; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import org.joda.time.LocalDate; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
public class JodaTimeSerializer extends JsonSerializer<LocalDate> { | ||
@Override | ||
public void serialize(LocalDate localDate, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { | ||
jsonGenerator.writeStartObject(); | ||
jsonGenerator.writeStringField("time", localDate.toString()); | ||
jsonGenerator.writeEndObject(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
autoconfig-example/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
no.bouvet.autoconfig.DebugFilterAutoconfig | ||
no.bouvet.autoconfig.DebugFilterAutoconfig, no.bouvet.autoconfig.JodaTimeAutoconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters