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 javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
* This class implements Author entity which forms * This class implements Author entity which forms
@ -69,6 +70,9 @@ public class Author {
regexp = regexCommon, regexp = regexCommon,
message = "Invalid characters" message = "Invalid characters"
) )
@JsonProperty(
value = "firstname"
)
private String firstName; private String firstName;
////////// //////////
@ -88,6 +92,9 @@ public class Author {
regexp = regexCommon, regexp = regexCommon,
message = "Invalid characters" message = "Invalid characters"
) )
@JsonProperty(
value = "lastname"
)
private String lastName; private String lastName;
// Omit from Jackson JSON serialization // 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 targetEntity = BookHash.class
) )
@PrimaryKeyJoinColumn @PrimaryKeyJoinColumn
private BookHash bookHash;
private BookHash bookhash;
//////////////////// ////////////////////
// Attributes with hard-coded constraints // Attributes with hard-coded constraints
@ -234,9 +234,13 @@ public class Book {
public void setId(Long id) { public void setId(Long id) {
this.id = 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) { public void setTitle(String title) {
@ -272,8 +276,9 @@ public class Book {
return id; return id;
} }
@JsonIgnore
public BookHash getBookHash() { public BookHash getBookHash() {
return bookHash;
return bookhash;
} }
public String getTitle() { public String getTitle() {
@ -321,7 +326,7 @@ public class Book {
@Override @Override
public String toString() { public String toString() {
return "[" + "id: " + this.id + ", " + return "[" + "id: " + this.id + ", " +
"bookhash_id: " + this.bookHash + ", " +
"bookhash_id: " + this.bookhash + ", " +
"title: " + this.title + ", " + "title: " + this.title + ", " +
"author: " + this.author + ", " + "author: " + this.author + ", " +
"year: " + this.year + ", " + "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 org.hibernate.annotations.Parameter;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
* This class implements BookHash entity which forms * This class implements BookHash entity which forms
@ -68,7 +69,7 @@ public class BookHash {
@OneToOne( @OneToOne(
cascade = { CascadeType.MERGE, CascadeType.REMOVE }, cascade = { CascadeType.MERGE, CascadeType.REMOVE },
fetch = FetchType.LAZY, fetch = FetchType.LAZY,
mappedBy = "bookHash",
mappedBy = "bookhash",
targetEntity = Book.class targetEntity = Book.class
) )
@PrimaryKeyJoinColumn( @PrimaryKeyJoinColumn(
@ -86,6 +87,9 @@ public class BookHash {
updatable = false, updatable = false,
nullable = false nullable = false
) )
@JsonProperty(
value = "hashid"
)
private String 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 @Modifying
@Query( @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 nativeQuery = true
) )
public void deleteByBookId(@Param("bookId") Long bookId);
public void deleteByBookId(@Param("bookid") Long bookId);
} }

Loading…
Cancel
Save