No Serializer Found for Class Org.Hibernate.Proxy.Pojo.Bytebuddy.Bytebuddyinterceptor

No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor

I came across this error while doing a tutorial with spring repository. It turned out that the error was made at the stage of building the service class for my entity.

In your serviceImpl class, you probably have something like:

    @Override
public YourEntityClass findYourEntityClassById(Long id) {
return YourEntityClassRepositorie.getOne(id);
}

Change this to:

    @Override
public YourEntityClass findYourEntityClassById(Long id) {
return YourEntityClassRepositorie.findById(id).get();
}

Basically getOne is a lazy load operation. Thus you get only a reference (a proxy) to the entity. That means no DB access is actually made. Only when you call it's properties then it will query the DB. findByID does the call 'eagerly'/immediately when you call it, thus you have the actual entity fully populated.

Take a look at this: Link to the difference between getOne & findByID

No serializer found for class org.hibernate.proxy.pojo.javassist.Javassist?

I had a similar problem with lazy loading via the hibernate proxy object. Got around it by annotating the class having lazy loaded private properties with:

@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})

I assume you can add the properties on your proxy object that breaks the JSON serialization to that annotation.

The problem is that entities are loaded lazily and serialization happens before they get loaded fully.

Hibernate.initialize(<your getter method>);

No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor, two method with same result but different output

Just replace getById with findById. The reason being that the first one is a lazy load operation and as a consequence you only get a reference (a proxy) to the entity. On the other hand, findById is a eagger load operation, and as a consequence, you immediately have the actual entity fully populated.

@PostMapping(path="/editSkill")
public @ResponseBody Iterable<Skill> editSkill(@RequestBody EditSkillRequest body) {
User u = userRepository.getUserBySessionToken(body.getSessionToken());
Skill s = skillRepository.findByid(body.getId());

s.setCost(body.getCost());
s.setName(body.getName());
s.setDescription(body.getDescription());
skillRepository.save(s);

return skillRepository.getAllSkills();
}

No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer

I was able to solve the issue by using the @JsonIgnoreProperties annotation.

// package and imports

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties({"hibernateLazyInitializer"})
@Entity
public class Pokemon implements Serializable {

// rest of code

}

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor

Not sure how this is working, but mixed of two things are working nicely. Took reference from here: Great Link

I added both @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) and @JsonIgnore Can not preserve the Bidirectional-Relationships after deserialization.

Here is my class now

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "stock", uniqueConstraints = { @UniqueConstraint(columnNames = "STOCK_NAME"),
@UniqueConstraint(columnNames = "STOCK_CODE") })
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Stock extends BaseEntity implements java.io.Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "STOCK_ID", unique = true, nullable = false)
private Integer stockId;

@Column(name = "STOCK_CODE", unique = true, nullable = false, length = 10)
private String stockCode;

@Column(name = "STOCK_NAME", unique = true, nullable = false, length = 20)
private String stockName;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "stock")
@JsonIgnore
private Set<StockDailyRecord> stockDailyRecords = new HashSet<>(0);

@Builder(builderMethodName = "sBuilder")
public Stock(Integer stockId, String stockCode, String stockName, Set<StockDailyRecord> stockDailyRecords,
Instant createdDate, Instant lastUpdateDate, String createUser, String lastUpdateUser) {
super(createdDate, lastUpdateDate, createUser, lastUpdateUser);
this.stockId = stockId;
this.stockCode = stockCode;
this.stockName = stockName;
this.stockDailyRecords = stockDailyRecords;
}
}

Note: Since it's @ManyToOne Relationship, so we cant not excepts StockDailyRecord from Stock, it will always be like getting Stock data from StockDailyRecord

You can also look Here

This is great: My Here

Is it better to do roll-your-own or ready-built forum software?

Advantages to rolling your own:

  • a non-standard custom-built system means you'll be less prone to "standard" attacks (e.g.: a vulnerability in PunBB) since bad guys tend to bother with exploit-hunting only on widely-deployed systems (more return on their investment)
  • absolute control over how your system works and looks
  • you'll learn a lot

Disadvantages:

  • you'll repeat mistakes other people have already solved
  • it'll take you longer to get up and running
  • long-term it'll be more maintenance (since you have to fix bugs & add features yourself).
  • you can't "leverage the community" -- if you choose an off-the-shelf forum that has a plugin system then there's a whole bunch of community add-ons that won't be available for your custom forum software.

There's a GIANT list of forum software on wikipedia -- there's most likely something in there that will suit your needs that you can get up and running quickly.

No serializer found Problem returning ResponseEntity including exception

This problem comes because entities are loaded lazily whereas the serialization process is performed before entities get loaded fully. Jackson tries to serialize the nested object but it fails as it finds JavassistLazyInitializer instead of the normal object.

As per your stack trace, You can suppress this error by adding the following configuration to your application.properties file:-

spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false

This will only hide the error but won't solve the issue. To solve the issue you can use the add-on module for Jackson which handles Hibernate lazy-loading. See more here:- Jackson-datatype-hibernate, how to configure Jackson-datatype-hibernate.



Related Topics



Leave a reply



Submit