Browse Source

Update JSON naming scheme

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.2-alpha
Pekka Helenius 4 years ago
parent
commit
4baea10349
4 changed files with 25 additions and 9 deletions
  1. +7
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java
  2. +11
    -6
      bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java
  3. +5
    -1
      bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java
  4. +2
    -2
      bookstore/src/main/java/com/fjordtek/bookstore/model/BookHashRepository.java

+ 7
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java View File

@ -18,6 +18,7 @@ import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* This class implements Author entity which forms
@ -69,6 +70,9 @@ public class Author {
regexp = regexCommon,
message = "Invalid characters"
)
@JsonProperty(
value = "firstname"
)
private String firstName;
//////////
@ -88,6 +92,9 @@ public class Author {
regexp = regexCommon,
message = "Invalid characters"
)
@JsonProperty(
value = "lastname"
)
private String lastName;
// Omit from Jackson JSON serialization


+ 11
- 6
bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java View File

@ -103,7 +103,7 @@ public class Book {
targetEntity = BookHash.class
)
@PrimaryKeyJoinColumn
private BookHash bookHash;
private BookHash bookhash;
////////////////////
// Attributes with hard-coded constraints
@ -234,9 +234,13 @@ public class Book {
public void setId(Long id) {
this.id = id;
}
public void setBookHash(BookHash bookHash) {
this.bookHash = bookHash;
/*
@JsonProperty(
value = "bookhash"
)
*/
public void setBookHash(BookHash bookhash) {
this.bookhash = bookhash;
}
public void setTitle(String title) {
@ -272,8 +276,9 @@ public class Book {
return id;
}
@JsonIgnore
public BookHash getBookHash() {
return bookHash;
return bookhash;
}
public String getTitle() {
@ -321,7 +326,7 @@ public class Book {
@Override
public String toString() {
return "[" + "id: " + this.id + ", " +
"bookhash_id: " + this.bookHash + ", " +
"bookhash_id: " + this.bookhash + ", " +
"title: " + this.title + ", " +
"author: " + this.author + ", " +
"year: " + this.year + ", " +


+ 5
- 1
bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java View File

@ -18,6 +18,7 @@ import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* This class implements BookHash entity which forms
@ -68,7 +69,7 @@ public class BookHash {
@OneToOne(
cascade = { CascadeType.MERGE, CascadeType.REMOVE },
fetch = FetchType.LAZY,
mappedBy = "bookHash",
mappedBy = "bookhash",
targetEntity = Book.class
)
@PrimaryKeyJoinColumn(
@ -86,6 +87,9 @@ public class BookHash {
updatable = false,
nullable = false
)
@JsonProperty(
value = "hashid"
)
private String hashId;


+ 2
- 2
bookstore/src/main/java/com/fjordtek/bookstore/model/BookHashRepository.java View File

@ -30,9 +30,9 @@ public interface BookHashRepository extends CrudRepository<BookHash, String> {
*/
@Modifying
@Query(
value = "DELETE FROM BOOK_HASH i WHERE i.book_id = :bookId",
value = "DELETE FROM BOOK_HASH i WHERE i.book_id = :bookid",
nativeQuery = true
)
public void deleteByBookId(@Param("bookId") Long bookId);
public void deleteByBookId(@Param("bookid") Long bookId);
}

Loading…
Cancel
Save