Questions tagged [pojo]

POJO is an acronym for Plain Old Java Object. The name is used to emphasize that a given object is an ordinary Java Object, not a special object, and in particular not an Enterprise JavaBean.

POJO (Plain Old Java Object) is mainly used to denote a Java object which does not follow any of the major Java object models, conventions, or frameworks such as EJB.

The term continues the pattern of older terms for technologies that do not use fancy new features, such as POTS (Plain Old Telephone Service) in telephony, PODS (Plain Old Data Structures) that are defined in C++ but use only C language features, and POD (Plain Old Documentation) in Perl. The equivalent to POJO on the .NET framework is Plain Old CLR Object (POCO). For PHP, it is Plain Old PHP Object (POPO).

1840 questions
50
votes
11 answers

How to map the result set of a JPA NativeQuery to a POJO using SqlResultSetMapping

I am attempting to map the results of a Native query to a POJO using @SqlResultSetMapping with @ConstructorResult. Here is my code: @SqlResultSetMapping(name="foo", classes = { @ConstructorResult( targetClass =…
mhlandry
  • 675
  • 1
  • 6
  • 14
50
votes
1 answer

Jackson JSON Deserialization with Root Element

I am having a question with Jackson that I think should be simple to solve, but it is killing me. Let's say I have a java POJO class that looks like this (assume Getters and Setters for me): class User { private String name; private Integer…
Sam Stern
  • 24,624
  • 13
  • 93
  • 124
49
votes
5 answers

Using wrapper Integer class or int primitive in hibernate mapping

In the company that I work for we have this major discussion on whether it should be better to use wrapping classes for primitives (java.lang.Integer, java.lang.Long) or whether to use the primitive types directly in the POJOs that map Entities to…
vanvasquez
  • 939
  • 1
  • 10
  • 18
45
votes
12 answers

ArrayList - How to modify a member of an object?

I have a number of Customer objects stored in an ArrayList. My Customer class has 2 data members: Name and Email. Now I want to modify just the Email for Customer "Doe". Now if "Doe" is located at index 3 in the list, I know I can write this…
user1318796
  • 461
  • 1
  • 4
  • 5
44
votes
10 answers

Create POJO Class for Kotlin

I want to create POJO class for Kotlin, as we know that www.jsonschema2pojo.org converts JSON to POJO so we can use it with gson. Anyone know how to create Gson POJO for Kotlin QUICKLY? Edited: I know its use Data classes, but is there any simplest…
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
40
votes
17 answers

JUnit tests for POJOs

I work on a project where we have to create unit tests for all of our simple beans (POJOs). Is there any point to creating a unit test for POJOs if all they consist of is getters and setters? Is it a safe assumption to assume POJOs will work about…
Ryan Thames
  • 3,204
  • 6
  • 31
  • 32
34
votes
4 answers

POJO's versus Cursors in Android

I usually tend to define the model layer of my apps using POJO's, such as Article, Comment, etc. I was about to implement an AlphabetIndexer in the adapter of one of my ListViews. Right now this adapter accepts a Collection of Articles, which I…
benvd
  • 5,776
  • 5
  • 39
  • 59
30
votes
10 answers

Is there a library to convert Java POJOs to and from JSON and XML?

I have an object graph that I would like to convert to and from JSON and XML, for the purposes of creating a REST-style API. It strikes me that someone must have done this already, but a quick search using Google and Stack Overflow reveals…
Darren Hague
  • 948
  • 2
  • 8
  • 8
30
votes
8 answers

What is the difference between POJO (Plain Old Java Object) and DTO (Data Transfer Object)?

I cannot find difference between them. Does anyone know how to differentiate them?
d1ck50n
  • 1,331
  • 2
  • 16
  • 20
28
votes
6 answers

Is there any way to declare final fields for Hibernate-managed objects?

I'm just getting started with Hibernate, and all the examples I'm seeing so far look pretty much like the tutorial in the Hibernate documentation: package org.hibernate.tutorial.domain; import java.util.Date; public class Event { private Long…
Kyle Krull
  • 1,618
  • 2
  • 18
  • 25
28
votes
10 answers

Android:dynamically pass model class to retrofit callback

In retrofit to map json response to pojo usually we do this @POST Call getDataFromServer(@Url String url, @Body HashMap hashMap); ApiCalls api = retrofit.create(ApiCalls.class); Call call =…
Rajesh Gosemath
  • 1,812
  • 1
  • 17
  • 31
28
votes
3 answers

Serialize Java List to XML using Jackson XML mapper

Hi I need to create an XML from JAVA using Jackson-dataformat XMLMapper. The XML should be like 1 Mighty Pulpo austin TX
Sharmistha Sinha
  • 315
  • 1
  • 5
  • 12
25
votes
8 answers

Generate setters that return self in Eclipse

I'd like to have my setters so that I can chain them like: myPojo.setX(x).setY(y); Usually I generate setters with Eclipse but unfortunately code template for setters allows me to change only the body of the setter, not the signature. What would be…
vertti
  • 7,539
  • 4
  • 51
  • 81
23
votes
7 answers

getters and setters performing additional logic

I have a Java class which represents the correlation between two elements (typical POJO): public class Correlation { private final String a; private final String b; private double correlation; public Correlation(String a, String…
eliocs
  • 18,511
  • 7
  • 40
  • 52
21
votes
9 answers

What is the exact meaning of invasive? and what makes Spring non-invasive?

I'm new to the spring framework. In most of the Spring tutorials I saw, Spring is described as "non-invasive". What is meant by invasive? What are the merits of using Spring in Java and what makes it non-invasive?
JackVimal
  • 355
  • 1
  • 4
  • 13