2

I am using Jackson to serialize Java objects for rest api. In Java I have an User class from which inherits Admin class. If I request data from ReactJS through method that returns Collection<User> I get only id for Admin objects.

Here is my User class:

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@NamedQueries(
        @NamedQuery(name = "User.findByName",
            query = "SELECT u FROM User u WHERE u.firstName = :firstName AND u.lastName = :lastName"))
@Entity
@Table(name = "users")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "user_type")
public class User extends AbstractEntity {

@Basic(optional = false)
@Column(nullable = false, name = "first_name")
private String firstName;

@Basic(optional = false)
@Column(nullable = false, name = "last_name")
private String lastName;

@Basic(optional = false)
@Column(nullable = false, unique = true)
private String email;
...

Then I have Admin class:

@Entity
public class Admin extends User {
}

I expect to receive JSON objects in same form for Admin as for User, but Admin objects are serialized just with id and nothing else.

Does it require any additional configuration for Jackson?

I guess it has something incommon with this question

Community
  • 1
  • 1
Jakub Gruber
  • 745
  • 1
  • 11
  • 27
  • I don't see getters in your code. If fields do not have getters they will not be serialized. – Dmitry Gorkovets Jan 14 '17 at 19:42
  • Sorry, of course there are getters, setters and default constructors. I didn't want to share whole class, because it's quite long. However, I do not have getters/setters in Admin class, but methods of super class should be use in thah case. – Jakub Gruber Jan 14 '17 at 19:44

0 Answers0