Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@JsonFormat.pattern is ignored for java.sql.Date valued properties #1407

Closed
sangpire opened this issue Oct 9, 2016 · 4 comments
Closed

@JsonFormat.pattern is ignored for java.sql.Date valued properties #1407

sangpire opened this issue Oct 9, 2016 · 4 comments
Milestone

Comments

@sangpire
Copy link

sangpire commented Oct 9, 2016

Hi
thank you for share a awesome library.

I am using version 2.6.7.
Here is failed test which shows that @JsonFormat is ignored pattern attribute.

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import java.sql.Date;
import static org.junit.Assert.assertEquals;

public class JsonFormatTest {

    public class Person {
        @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.mm.dd")
        public Date dateOfBirth;
    }

    @Test
    public void JsonFormatPatternTest() throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        Person i = new Person();
        i.dateOfBirth = Date.valueOf("1980-04-14");
        assertEquals("{\"dateOfBirth\":\"1980.04.14\"}", objectMapper.writeValueAsString(i));
    }
}

And the results of running the test:

org.junit.ComparisonFailure: 
Expected :{"dateOfBirth":"1980.04.14"}
Actual   :{"dateOfBirth":"1980-04-14"}

I don't know exactly the reason.
But I have a doubt in a line of code.
https://github.com/FasterXML/jackson-databind/blob/2.6/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java#L36

Which method ignored the customFormat param.

Thank you.

@cowtowncoder cowtowncoder changed the title @JsonFormat is ignored pattern attributes. @JsonFormat.pattern is ignored for java.sql.Date valued properties Oct 11, 2016
@cowtowncoder
Copy link
Member

Yes, it is likely that handling of java.sql.Date is missing some of newer features, and support should be added.

@sangpire
Copy link
Author

@cowtowncoder If you agree I will implement the fix and create a PR for it, after work 😅

@cowtowncoder
Copy link
Member

@sangpire that would be great! Let me know if you need help with sample code; existing java.util.Calendar handling should work as base, or (de)serializer(s) from Joda module.

@sangpire
Copy link
Author

Sorry for annoying messages;;

@cowtowncoder cowtowncoder added this to the 2.9.0 milestone Jan 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants