#1147 - Make sure we explicitly expose all media type model properties.

Jackson can be configured to not auto-detect properties on objects to be rendered, requiring them to be explicitly annotated with @JsonProperty to be exposed. In such a configuration setup, some of our model types do not work properly as so far we have expected public properties to be included automatically.

This commit changes that to explicitly include @JsonProperty on all of the getter methods exposed.
This commit is contained in:
Oliver Drotbohm
2019-12-09 09:38:19 +01:00
parent 452189edd8
commit 7744bda4b1
11 changed files with 41 additions and 12 deletions

View File

@@ -20,11 +20,12 @@ import java.io.Writer;
import org.junit.jupiter.api.BeforeEach;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Base class to test objects against the Jackson 2.0 {@link ObjectMapper}.
*
*
* @author Oliver Gierke
* @author Jon Brisbin
* @author Greg Turnquist
@@ -36,6 +37,11 @@ public abstract class AbstractJackson2MarshallingIntegrationTest {
@BeforeEach
void setUp() {
mapper = new ObjectMapper();
mapper.disable(MapperFeature.AUTO_DETECT_CREATORS) //
.disable(MapperFeature.AUTO_DETECT_FIELDS) //
.disable(MapperFeature.AUTO_DETECT_GETTERS) //
.disable(MapperFeature.AUTO_DETECT_IS_GETTERS) //
.disable(MapperFeature.AUTO_DETECT_SETTERS);
}
protected String write(Object object) throws Exception {

View File

@@ -2,9 +2,13 @@ package org.springframework.hateoas.mediatype.hal;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import com.fasterxml.jackson.annotation.JsonProperty;
@Data
@Getter(onMethod = @__(@JsonProperty))
@NoArgsConstructor
@AllArgsConstructor
public class SimplePojo {