Spring JPA audting is not invoked - spring

I have implemented spring data jpa auditing. Below is my configuration file
#Configuration
#ComponentScan(basePackages = "com.myapplication.test")
#EnableWebMvc
#EnableTransactionManagement
#EnableJpaRepositories(basePackages = "com.myapplication.test.repository")
#EnableJpaAuditing(auditorAwareRef = "auditorProvider", dateTimeProviderRef = "dateTimeProvider")
#EnableSpringDataWebSupport
public class ApplicationConfiguration {
private static final Logger loggger = Logger.getLogger(ApplicationConfiguration.class);
#Autowired
private ConfigurationProperties configProps;
#Bean("auditorProvider")
public AuditorAware<Integer> auditorProvider() {
return () -> {
AuthenticationToken authentication = (AuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
return (authentication != null && authentication.isAuthenticated()) ? authentication.getUser().getUserId() : null;
};
}
#Bean
public DateTimeProvider dateTimeProvider() {
return () -> GregorianCalendar.from(ZonedDateTime.now());
}
}
Here is my entity super class
#MappedSuperclass
#EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {
#JsonIgnore
#Column(name = "created_by", updatable = false)
private Integer createdBy;
#JsonIgnore
#CreationTimestamp
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "created_on", updatable = false)
private Date createdOn;
#JsonIgnore
#Column(name = "last_updated_by")
private Integer updatedBy;
#JsonIgnore
#UpdateTimestamp
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "last_updated_on")
private Date updatedOn;
}
auditorProvider is getting the user id from the Spring Security context. I have used spring-security-oauth2.
below the versions of the libraries I am having
<spring.version>4.3.6.RELEASE</spring.version>
<hibernate.version>5.2.9.Final</hibernate.version>
<springsecurity.version>4.1.4.RELEASE</springsecurity.version>
<springsecurityoauth2.version>2.0.12.RELEASE</springsecurityoauth2.version>
When I save an entity the auditing methods are not getting called(in debug) and created/updated fields are not updated in the table.

Instead of using the hibernate annotations, you should use the spring data ones like:
#Column(name = "created_date", nullable = false, updatable = false)
#CreatedDate
private long createdDate;
#Column(name = "modified_date")
#LastModifiedDate
private long modifiedDate;
This always worked for me, as specified in this tutorial: Jpa Auditing

Related

Spring data jpa CRUDRepository/ JPArepository saveall can not get id (non primary key)

I am fetching data from FB marketing API and trying to save in DB. I am able to save data in the DB using CrudRepository or JpaRepository -> saveall method, but when trying to fetch the id in response of saveall, I am getting id as null. When I see in the h2-console, able to see the auto increment value after the completion of transaction.
Note: id is not used as primary key #Id. accountId is used as primary key.
Model:
#Entity
#Table(name = "accounts")
#Data
#ToString(onlyExplicitlyIncluded = true)
public class Account implements Serializable{
#JsonIgnore
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(columnDefinition = "integer auto_increment",insertable = false)
private Long id;
#JsonProperty("account_id")
#Column(name = "account_id")
#Id
private String accountId;
#Column(name = "account_status")
private int accountStatus;
#JsonProperty("timezone_id")
#Column(name = "timezone_id")
private int timezoneId;
private int timezoneOffsetUtc;
private String currency;
#Column(name = "timezone_name")
#JsonProperty("timezone_name")
private String timezoneName;
private String name;
#Column(name = "created_on",nullable = false, updatable = false)
#CreationTimestamp
private LocalDateTime createdOn;
#Column(name = "updated_on")
#UpdateTimestamp
private LocalDateTime updatedOn;
}
Repository:
#Repository()
public interface AccountRepository extends CrudRepository<Account, String> {
}
Tried with JpaRepository<Account, Long> too and flush after saving..but still getting id null in return list response of saveall()
Service:
#Service
public class AccountsService {
#Autowired
private AccountRepository repository;
#Override
#Transactional
public List<Account> saveAll(List<Account> accounts) {
//in case of JpaRepository
List<Account> savedAccounts= repository.saveAll(accounts);
repository.flush();
return savedAccounts;
//in case of CrudRepository
return (List<Account>)repository.saveAll(accounts);
}
}
when executing this
//accountsList received from FB API
List<Account> savedList=iAccountsService.saveAll(accountsList);
savedList.get(0).getId() **//this is coming as null**
Any sort of help is appreciated.
In your entity class :
Use this #GeneratedValue(strategy = GenerationType.IDENTITY)
public class Account implements Serializable{
#JsonIgnore
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(unique = true, nullable = false, insertable = false, updatable = false)
private Long id;
}

ManyToOne gives null in Spring Boot Test

I have an entity UserMicroService like this:
#Entity
#Table(name = "user_service")
public class UserMicroService extends BaseAccountEntity<Long> {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String userId;
#ManyToOne(optional = false)
#JoinColumn(name = "userId", insertable = false, updatable = false)
private User user;
// getters and setters
}
I need both userId and user fields. To achieve this, I have to mark my user field annotation with additional parameters:
optional = false
insertable = false, updatable = false
And it works just perfectly in the app. But when I run Spring Boot Test, the user field is null.
#Transactional
#SpringBootTest
#ActiveProfiles("test")
#RunWith(SpringRunner.class)
public class TelegramNotificationServiceIT {
#Autowired
private TelegramNotificationService telegramNotificationService;
#MockBean
private TelegramNotificationQueueService telegramNotificationQueueService;
#Test
public void processServiceNotifications_noUsers() {
telegramNotificationService.processServiceNotifications();
verify(telegramNotificationQueueService, times(0)).add(any());
}
}
The repository is Spring Data Jpa with method:
List<UserMicroService> findByServiceAndBalanceAndCurrentEndDateBetween(ServiceName service, BigDecimal balance, LocalDateTime from, LocalDateTime to);

Auto populate created_date, last_modified_date, created_by and last_modified_by in entity : Hibernate with JPA

I am new to Hibernate and JPA. I have several entities, each of which contains following four columns:
1. created_by
2. last_modified_by
3. created_date
4. last_modified_date
I would like these columns to get auto-populated while saving the associated entity.
Two sample entities are as follows:
Entity 1:
#Entity
#Table(name = "my_entity1")
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MyEntity1 implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column(name = "name")
private String name;
#Column(name = "created_by")
private String createdBy;
#Column(name = "last_modified_by")
private String lastModifiedBy;
#Column(name = "created_date")
private Instant createdDate;
#Column(name = "last_modified_date")
private String lastModifiedDate;
}
Entity 2:
#Entity
#Table(name = "my_entity2")
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MyEntity2 implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column(name = "description")
private String description;
#Column(name = "created_by")
private String createdBy;
#Column(name = "last_modified_by")
private String lastModifiedBy;
#Column(name = "created_date")
private Instant createdDate;
#Column(name = "last_modified_date")
private String lastModifiedDate;
}
In this context, I have gone through following posts: How to autogenerate created or modified timestamp field?, How can you make a created_at column generate the creation date-time automatically like an ID automatically gets created?.
I am getting how to capture the dates fields but I cannot understand how to capture created_by and last_modified_by.
Auditing Author using AuditorAware and Spring Security...
To tell JPA about currently logged in user we will need to provide an
implementation of AuditorAware and override getCurrentAuditor()
method. And inside getCurrentAuditor() we will need to fetch currently
logged in user.
Like this:
public class AuditorAwareImpl implements AuditorAware<String> {
#Override
public String getCurrentAuditor() {
return "TestUser";
// Can use Spring Security to return currently logged in user
// return ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername()
}
}
Now enable jpa auditing by using #EnableJpaAuditing
#Configuration
#EnableJpaAuditing(auditorAwareRef = "auditorAware")
public class JpaConfig {
#Bean
public AuditorAware<String> auditorAware() {
return new AuditorAwareImpl();
}
}
Look at this to get more details....

How to get an Authenticated User's Details in Spring Security OAuth2

I am unable to extract the current logged in user in Spring Security OAuth2. My goal is to extract the user when the create event on ClientSuggestion entity is triggered and persist it to the database.
Employee.java
#Entity
#Table(name = "er_employee")
public class Employee implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id")
private Long id;
#Column(name = "username", unique = true)
#NotNull
#Size(max = 10)
private String username;
#Column(name = "password_hash")
#NotNull
#Size(min = 8, max = 512)
private String password;
#Column(name = "email_verification_token")
#Size(max = 512)
private String emailVerificationToken;
#Column(name = "password_reset_token")
#Size(max = 512)
private String passwordResetToken;
#Column(name = "active")
#NotNull
private boolean active;
#Column(name = "is_deleted")
#NotNull
private boolean deleted;
#Column(name = "date_of_creation")
#Temporal(TemporalType.TIMESTAMP)
#NotNull
private Date dateOfCreation;
#OneToMany(mappedBy = "employee")
private List<ClientSuggestion> clientSuggestions;
//Constructors
//Getters ans setters
}
ClientSuggestion.java
#Entity
#Table(name = "er_suggestion")
public class ClientSuggestion implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id")
private Long id;
#Column(name = "content", unique = true)
#NotNull
#Size(max = 200)
private String suggestion;
#ManyToOne
#JoinColumn(name = "employee_id")
private Employee employee;
//Constructors
//Getters ans setters
}
EmployeeRepository.java
public interface EmployeeRepository extends CrudRepository<Employee, Long> {
ClientSuggestionRepository .java
public interface ClientSuggestionRepository extends CrudRepository<ClientSuggestion, Long> {
}
The event handler
#Component
#RepositoryEventHandler(ClientSuggestion.class)
public class ClientSuggestionEventHandler {
Employee employee= (Employee ) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
#HandleBeforeCreate
public void handleClientSuggestionBeforeCreate(ClientSuggestion cs) {
cs.setDeleted(false);
cs.setActive(true);
cs.setPasswordResetToken(Encryptor.generateHash(cs.getPassword, 512));
cs.setEmployee(employee);
}
}
The bean, ClientSuggestionEventHandler, is registered in a configuration class. When I tried running the project, NullPointerException exception is thrown. I wish to find out how to get the current logged employee.
I'm new to Spring Security OAuth2. Thanks.
In Employee.java implement org.springframework.security.core.userdetails.UserDetails class
Employee.java
#Entity
#Table(name = "er_employee")
public class Employee implements Serializable, UserDetails {
And then use Employee employee= (Employee) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

Spring 4 ZoneDateTime Restful recursive output

I am new on Java 8 and Spring 4
i have tried to implement spring boot with module (Spring boot web, Spring boot jpa)
i have tried to implement JpaAuditing on my entity with the following code:
//AbstractAuditedEntity.class
#MappedSuperclass
public class AbstractAuditedEntity {
#CreatedBy
#Column(name = "CREATED_BY")
private String createdBy;
// #Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
#CreatedDate
#DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
#Column(name = "CREATED_DATE")
// #Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private ZonedDateTime createdDate;
#LastModifiedBy
#Column(name = "LAST_MODIFIED_BY")
private String lastModifiedBy;
// #Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
#DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
#LastModifiedDate
#Column(name = "LAST_MODIFIED_DATE")
// #Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
private ZonedDateTime lastModifiedDate;
/*setter getter are omitted*/
}
and the User entity with the following code :
#Entity
#Table(name = "common_user")
public class User extends AbstractAuditedEntity {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "ID")
private Long id;
/*other fields are omitted*/
}
and my controller :
#RestController
public class UserCtrl {
#Autowired
UserRepository userRepository;
#RequestMapping(value = "/user", method = RequestMethod.GET)
#ResponseBody
public User index() {
User one = userRepository.findOne(1L);
return one;
}
}
the result is of field createdDate and lastModifiedDate are recursive :(
{"createdBy":"SYSTEM","createdDate":{"offset":{"totalSeconds":25200,"rules": {"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:00"},"zone":{"id":"Asia/Jakarta","rules":{"fixedOffset":false,"transitionRules":[],"transitions":[{"offsetBefore":{"totalSeconds":25632,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:07:12"},"offsetAfter":{"totalSeconds":26400,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:20"},"dateTimeAfter":{"hour":0,"minute":0,"nano":0,"second":0,"month":"JANUARY","year":1924,"dayOfMonth":1,"dayOfWeek":"TUESDAY","dayOfYear":1,"monthValue":1,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":768,"zero":false,"negative":false,"nano":0,"units":["SECONDS","NANOS"]},"gap":true,"overlap":false,"dateTimeBefore":{"hour":23,"minute":47,"nano":0,"second":12,"month":"DECEMBER","year":1923,"dayOfMonth":31,"dayOfWeek":"MONDAY","dayOfYear":365,"monthValue":12,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-1451719200,"nano":0}},{"offsetBefore":{"totalSeconds":26400,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:20"},"offsetAfter":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"dateTimeAfter":{"hour":0,"minute":10,"nano":0,"second":0,"month":"NOVEMBER","year":1932,"dayOfMonth":1,"dayOfWeek":"TUESDAY","dayOfYear":306,"monthValue":11,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":600,"zero":false,"negative":false,"nano":0,"units":["SECONDS","NANOS"]},"gap":true,"overlap":false,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"NOVEMBER","year":1932,"dayOfMonth":1,"dayOfWeek":"TUESDAY","dayOfYear":306,"monthValue":11,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-1172906400,"nano":0}},{"offsetBefore":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"offsetAfter":{"totalSeconds":32400,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+09:00"},"dateTimeAfter":{"hour":1,"minute":30,"nano":0,"second":0,"month":"MARCH","year":1942,"dayOfMonth":23,"dayOfWeek":"MONDAY","dayOfYear":82,"monthValue":3,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":5400,"zero":false,"negative":false,"nano":0,"units":["SECONDS","NANOS"]},"gap":true,"overlap":false,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"MARCH","year":1942,"dayOfMonth":23,"dayOfWeek":"MONDAY","dayOfYear":82,"monthValue":3,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-876641400,"nano":0}},{"offsetBefore":{"totalSeconds":32400,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+09:00"},"offsetAfter":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"dateTimeAfter":{"hour":22,"minute":30,"nano":0,"second":0,"month":"SEPTEMBER","year":1945,"dayOfMonth":22,"dayOfWeek":"SATURDAY","dayOfYear":265,"monthValue":9,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":-5400,"zero":false,"negative":true,"nano":0,"units":["SECONDS","NANOS"]},"gap":false,"overlap":true,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"SEPTEMBER","year":1945,"dayOfMonth":23,"dayOfWeek":"SUNDAY","dayOfYear":266,"monthValue":9,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-766054800,"nano":0}},{"offsetBefore":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"offsetAfter":{"totalSeconds":28800,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+08:00"},"dateTimeAfter":{"hour":0,"minute":30,"nano":0,"second":0,"month":"MAY","year":1948,"dayOfMonth":1,"dayOfWeek":"SATURDAY","dayOfYear":122,"monthValue":5,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":1800,"zero":false,"negative":false,"nano":0,"units":["SECONDS","NANOS"]},"gap":true,"overlap":false,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"MAY","year":1948,"dayOfMonth":1,"dayOfWeek":"SATURDAY","dayOfYear":122,"monthValue":5,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-683883000,"nano":0}},{"offsetBefore":{"totalSeconds":28800,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+08:00"},"offsetAfter":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"dateTimeAfter":{"hour":23,"minute":30,"nano":0,"second":0,"month":"APRIL","year":1950,"dayOfMonth":30,"dayOfWeek":"SUNDAY","dayOfYear":120,"monthValue":4,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":-1800,"zero":false,"negative":true,"nano":0,"units":["SECONDS","NANOS"]},"gap":false,"overlap":true,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"MAY","year":1950,"dayOfMonth":1,"dayOfWeek":"MONDAY","dayOfYear":121,"monthValue":5,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-620812800,"nano":0}},{"offsetBefore":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"offsetAfter":{"totalSeconds":25200,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:00"},"dateTimeAfter":{"hour":23,"minute":30,"nano":0,"second":0,"month":"DECEMBER","year":1963,"dayOfMonth":31,"dayOfWeek":"TUESDAY","dayOfYear":365,"monthValue":12,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":-1800,"zero":false,"negative":true,"nano":0,"units":["SECONDS","NANOS"]},"gap":false,"overlap":true,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"JANUARY","year":1964,"dayOfMonth":1,"dayOfWeek":"WEDNESDAY","dayOfYear":1,"monthValue":1,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-189415800,"nano":0}}]}},"hour":15,"minute":37,"nano":576000000,"second":41,"month":"AUGUST","year":2014,"dayOfMonth":21,"dayOfWeek":"THURSDAY","dayOfYear":233,"monthValue":8,"chronology":{"calendarType":"iso8601","id":"ISO"}},"lastModifiedBy":"SYSTEM","lastModifiedDate":{"offset":{"totalSeconds":25200,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:00"},"zone":{"id":"Asia/Jakarta","rules":{"fixedOffset":false,"transitionRules":[],"transitions":[{"offsetBefore":{"totalSeconds":25632,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:07:12"},"offsetAfter":{"totalSeconds":26400,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:20"},"dateTimeAfter":{"hour":0,"minute":0,"nano":0,"second":0,"month":"JANUARY","year":1924,"dayOfMonth":1,"dayOfWeek":"TUESDAY","dayOfYear":1,"monthValue":1,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":768,"zero":false,"negative":false,"nano":0,"units":["SECONDS","NANOS"]},"gap":true,"overlap":false,"dateTimeBefore":{"hour":23,"minute":47,"nano":0,"second":12,"month":"DECEMBER","year":1923,"dayOfMonth":31,"dayOfWeek":"MONDAY","dayOfYear":365,"monthValue":12,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-1451719200,"nano":0}},{"offsetBefore":{"totalSeconds":26400,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:20"},"offsetAfter":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"dateTimeAfter":{"hour":0,"minute":10,"nano":0,"second":0,"month":"NOVEMBER","year":1932,"dayOfMonth":1,"dayOfWeek":"TUESDAY","dayOfYear":306,"monthValue":11,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":600,"zero":false,"negative":false,"nano":0,"units":["SECONDS","NANOS"]},"gap":true,"overlap":false,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"NOVEMBER","year":1932,"dayOfMonth":1,"dayOfWeek":"TUESDAY","dayOfYear":306,"monthValue":11,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-1172906400,"nano":0}},{"offsetBefore":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"offsetAfter":{"totalSeconds":32400,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+09:00"},"dateTimeAfter":{"hour":1,"minute":30,"nano":0,"second":0,"month":"MARCH","year":1942,"dayOfMonth":23,"dayOfWeek":"MONDAY","dayOfYear":82,"monthValue":3,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":5400,"zero":false,"negative":false,"nano":0,"units":["SECONDS","NANOS"]},"gap":true,"overlap":false,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"MARCH","year":1942,"dayOfMonth":23,"dayOfWeek":"MONDAY","dayOfYear":82,"monthValue":3,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-876641400,"nano":0}},{"offsetBefore":{"totalSeconds":32400,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+09:00"},"offsetAfter":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"dateTimeAfter":{"hour":22,"minute":30,"nano":0,"second":0,"month":"SEPTEMBER","year":1945,"dayOfMonth":22,"dayOfWeek":"SATURDAY","dayOfYear":265,"monthValue":9,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":-5400,"zero":false,"negative":true,"nano":0,"units":["SECONDS","NANOS"]},"gap":false,"overlap":true,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"SEPTEMBER","year":1945,"dayOfMonth":23,"dayOfWeek":"SUNDAY","dayOfYear":266,"monthValue":9,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-766054800,"nano":0}},{"offsetBefore":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"offsetAfter":{"totalSeconds":28800,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+08:00"},"dateTimeAfter":{"hour":0,"minute":30,"nano":0,"second":0,"month":"MAY","year":1948,"dayOfMonth":1,"dayOfWeek":"SATURDAY","dayOfYear":122,"monthValue":5,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":1800,"zero":false,"negative":false,"nano":0,"units":["SECONDS","NANOS"]},"gap":true,"overlap":false,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"MAY","year":1948,"dayOfMonth":1,"dayOfWeek":"SATURDAY","dayOfYear":122,"monthValue":5,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-683883000,"nano":0}},{"offsetBefore":{"totalSeconds":28800,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+08:00"},"offsetAfter":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"dateTimeAfter":{"hour":23,"minute":30,"nano":0,"second":0,"month":"APRIL","year":1950,"dayOfMonth":30,"dayOfWeek":"SUNDAY","dayOfYear":120,"monthValue":4,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":-1800,"zero":false,"negative":true,"nano":0,"units":["SECONDS","NANOS"]},"gap":false,"overlap":true,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"MAY","year":1950,"dayOfMonth":1,"dayOfWeek":"MONDAY","dayOfYear":121,"monthValue":5,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-620812800,"nano":0}},{"offsetBefore":{"totalSeconds":27000,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:30"},"offsetAfter":{"totalSeconds":25200,"rules":{"fixedOffset":true,"transitionRules":[],"transitions":[]},"id":"+07:00"},"dateTimeAfter":{"hour":23,"minute":30,"nano":0,"second":0,"month":"DECEMBER","year":1963,"dayOfMonth":31,"dayOfWeek":"TUESDAY","dayOfYear":365,"monthValue":12,"chronology":{"calendarType":"iso8601","id":"ISO"}},"duration":{"seconds":-1800,"zero":false,"negative":true,"nano":0,"units":["SECONDS","NANOS"]},"gap":false,"overlap":true,"dateTimeBefore":{"hour":0,"minute":0,"nano":0,"second":0,"month":"JANUARY","year":1964,"dayOfMonth":1,"dayOfWeek":"WEDNESDAY","dayOfYear":1,"monthValue":1,"chronology":{"calendarType":"iso8601","id":"ISO"}},"instant":{"epochSecond":-189415800,"nano":0}}]}},"hour":15,"minute":37,"nano":576000000,"second":41,"month":"AUGUST","year":2014,"dayOfMonth":21,"dayOfWeek":"THURSDAY","dayOfYear":233,"monthValue":8,"chronology":{"calendarType":"iso8601","id":"ISO"}},"id":1,"firstName":"adil","lastName":"ramdan","username":"admin","password":null,"email":"adil.ramdan#gmail.com","photo":"pp.jpg","group":null,"shaPassword":null,"authToken":null}
How to format ZoneDateTime in the Restful ?thanks before
That's not actually recursive; you can see for yourself by posting that json string into http://jsonformatter.curiousconcept.com/.
If you want to use ZonedDateTime and you don't want all of its properties converted to JSON, you might add #JsonIgnore to the field and then adding getters for each field that you want. For example:
#JsonIgnore
#CreatedDate
#DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
#Column(name = "CREATED_DATE")
private ZonedDateTime createdDate;
public Month getMonthCreated(){
return createdDate.getMonth();
}

Resources