Issue: API Returning Empty JSON Objects {}
facing an issue in my Spring Boot project. My API for fetching products is returning empty objects: [{}, {}, {}, {}] But I have verified that data exists in my H2 database.
47 Replies
⌛
This post has been reserved for your question.
Hey @Shruti! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
hi
can you show the code
the service one
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
package com.example.EcomTutDemo11.service;
import com.example.EcomTutDemo11.model.Product;
import com.example.EcomTutDemo11.repo.ProductRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
This message has been formatted automatically. You can disable this using
/preferences
.show the product repo
and the controller
also shos the product class
show
product repo
package com.example.EcomTutDemo11.repo;
import com.example.EcomTutDemo11.model.Product;
import jakarta.persistence.criteria.CriteriaBuilder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
This message has been formatted automatically. You can disable this using
/preferences
.service package com.example.EcomTutDemo11.service;
import com.example.EcomTutDemo11.model.Product;
import com.example.EcomTutDemo11.repo.ProductRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
This message has been formatted automatically. You can disable this using
/preferences
.model package com.example.EcomTutDemo11.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.*;
import java.math.BigDecimal;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity
This message has been formatted automatically. You can disable this using
/preferences
.controller package com.example.EcomTutDemo11.controller;
import com.example.EcomTutDemo11.model.Product;
import com.example.EcomTutDemo11.service.ProdcutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/api")
This message has been formatted automatically. You can disable this using
/preferences
.can you try using any other database than h2
maybe the database itself is the problem
beacuse the code looks good
oh
try adding
@Shruti add the generated value annotation to your id and see if it helps
i am using h2 only
i added this @GeneratedValue(strategy = GenerationType.IDENTITY) but no difference
h2 database isnt good as a real one
its good just for testing
@dan1st can you take a look
h2 doesnt return objects
Can I see the DB configuration (application.properties) and the code inserting objects?
If it is an automated test,I'd like to see that as well
If applicable, it would be useful to see the content of the relevant table
just because SO is down after they've migrated to GCP yesterday?
application properties spring.application.name=EcomTutDemo11
server.port=9092
spring.datasource.url=jdbc:h2:mem:ecom
sspring.datasource.driver-class-name=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.defer-datasource-initialization=true
data.sql INSERT INTO Product (id, name, description, brand, price, category, release_date, available, quantity) VALUES
(1, 'Smartphone', 'Latest model with high performance', 'Samsung', 69999.99, 'Electronics', '2025-04-01', true, 50),
(2, 'Laptop', 'Ultra-fast gaming laptop', 'Asus', 129999.99, 'Computers', '2025-03-15', true, 20),
(3, 'Headphones', 'Noise-cancelling wireless headphones', 'Sony', 14999.50, 'Accessories', '2025-02-20', true, 100),
(4, 'Smartwatch', 'Feature-rich smartwatch with health tracking', 'Apple', 39999.00, 'Wearables', '2025-01-10', true, 30);


oh so you are getting the entries but cannot find anything there
wait, is there lombok?
yep, it's because of lombok
I'd show you my own SO answer but SO is down rn
First update to the latest lombok version
and then add
<proc>full</proc>
to the <configuration>
of the maven-compiler-plugin
@Shruti
or don't use lombok if you don't want your application to break lolyes lol
it's really annoying because I have written a good Stack Overflow answer explaining the issue
extended april fools joke
they migrated their servers to Google Cloud yesterday so take it as you want
if gpt wasnt a thing all engineers would be doomed
though it seems that the other SE sites got issues as well
Yeah I used lombok.. previously it was giving mvn not found then I reinstalled everything..then it gave jdk not found because it was pointing to older version..I resolved that and now this ..
for old JDK versions, it "works"
for newer JDK versions, you need to change the things I mentioned
though there are alternatives to
<proc>full</proc>
for more details: https://stackoverflow.com/a/79210588/10871900
Stack Overflow
Build Failure: @Data Annotation won't regonize by Maven
I consider that my maven has problems with the annotation @Data from lombok.
About the project: Java 23 Spring Boot Version 3.3.4 also using Intellij ultimate
The error appears after like mvn comp...
is this tag the replacement for the annotation processor tag
in older jdks
no
or does it have some extra
oh ok
you can use the annotation processor tag instead
-proc:full
pretty much means "compile and register annotation processors automatically"💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
same issue


i added this @Override
This message has been formatted automatically. You can disable this using
/preferences
.thank you so much
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
@Shruti upload whole pom
pom
do you have this enabled?
@Shruti
yes i did that already
Can you try with java 11?
he said it works already
Ahh I missed it
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.