same as subject.
Jackson version: 2.9.8

Entity
@Getter
@Setter
public class GeneralUser {
    private String name;
    private String password;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:SS")
    private Date createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:SS")
    private Date modifiedTime;
}

MixInClass
public interface IgnoreCreateAndModifiedTime {
    @JsonIgnore
    String getName();
    @JsonIgnore
    Date getModifiedTime();
}

Test
@Test
public void mixTest() throws JsonProcessingException {
    GeneralUser generalUser = new GeneralUser();
    generalUser.setCreateTime(new Date());
    generalUser.setModifiedTime(new Date());
    generalUser.setName("test");
    generalUser.setPassword("123456");
    System.out.println(new ObjectMapper()
            .addMixIn(GeneralUser.class, IgnoreCreateAndModifiedTime.class)
            .writeValueAsString(generalUser));
}

result
{"password":"123456","createTime":"2019-05-16 
07:23:353","modifiedTime":"2019-05-16 07:23:353"}

and @JsonIgnoreProperties can work
@JsonIgnoreProperties({"modifiedTime"})

result
{"password":"123456","createTime":"2019-05-16 07:26:122"}




-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/8fbb1fbc-6823-4ef8-86e1-f73cb52f5ba3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to