0

Entity

@Data
@Accessors(chain = true, fluent = true)
@Entity
@Table(name = "T_NOTE")
@Access(AccessType.FIELD)
public class Note implements Serializable
{
    @Id
    @GeneratedValue
    private Long id;

    private Date date;
    @Column(length = 2000)
    private String content;
    private String title;
    private String weather;
}

Repository

@RepositoryRestResource(collectionResourceRel = "note", path = "note")
public interface NoteRepository extends AbstractRepository<Note, Long>
{

}

GET http://localhost:8080/note/2

{
    "_links": {
        "self": {
            "href": "http://localhost:8080/note/2"
        }
    }
}

No entity field data, why?

EIDT

After I add standard setter/getter, everything is ok now.

public Long getId()
{
    return id;
}

public void setId(Long id)
{
    this.id = id;
}

public Date getDate()
{
    return date;
}

public void setDate(Date date)
{
    this.date = date;
}

public String getContent()
{
    return content;
}

public void setContent(String content)
{
    this.content = content;
}

public String getTitle()
{
    return title;
}

public void setTitle(String title)
{
    this.title = title;
}

public String getWeather()
{
    return weather;
}

public void setWeather(String weather)
{
    this.weather = weather;
}

Is this cause by jackson mapper ? How can I use fluent API with this ?Why not just use reflection to generate JSON ?

EDIT

What I need is this configuration

@Configuration
@Import(RepositoryRestMvcConfiguration.class)
public class ShoweaRestMvcConfiguration extends RepositoryRestMvcConfiguration
{
    @Override
    protected void configureJacksonObjectMapper(ObjectMapper mapper)
    {
        mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
        mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    }
}

Caused by this

Community
  • 1
  • 1
wener
  • 7,191
  • 6
  • 54
  • 78

1 Answers1

1

@Accessors is probably stepping over the @Data annotation, and with fluent = true it generates getters with the same name as the field, like id() and date() (@Accessor documentation). That's why Spring doesn't see any of the fields.

I think you can safely remove both @Accessors and @Access, since @Access's takes the default value from id (if you annotated the field, it will be FIELD, if you annotated the getter, it will be PROPERTY).

Predrag Maric
  • 23,938
  • 5
  • 52
  • 68
  • Yes, it works, I just add setter/getter not change the fluent accessor.updated the question, but why ? – wener Mar 16 '15 at 15:26