-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utility functionality and refactor (#254)
* add private * create json utils class * refactor object mapper to be in json util class * test package rename "util" --> "testutil" * add utility functions for base model classes * make string required type for keys * tests
- Loading branch information
Showing
44 changed files
with
305 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/info/movito/themoviedbapi/util/JsonUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package info.movito.themoviedbapi.util; | ||
|
||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
|
||
/** | ||
* JSON Utility. | ||
*/ | ||
public final class JsonUtil { | ||
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
|
||
private static final ObjectWriter MAP_WRITER = OBJECT_MAPPER.writerFor(Map.class); | ||
|
||
private JsonUtil() { | ||
} | ||
|
||
/** | ||
* Converts a Map to a JSON String. | ||
* | ||
* @param map the map to convert. | ||
* @return the json. | ||
*/ | ||
public static String toJson(Map<String, ?> map) { | ||
try { | ||
return MAP_WRITER.writeValueAsString(map); | ||
} | ||
catch (JsonProcessingException jpe) { | ||
throw new RuntimeException("json conversion failed", jpe); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/info/movito/themoviedbapi/util/ModelUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package info.movito.themoviedbapi.util; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import info.movito.themoviedbapi.model.core.NamedIdElement; | ||
import info.movito.themoviedbapi.model.core.NamedStringIdElement; | ||
|
||
/** | ||
* TMDB API Model Utility. | ||
*/ | ||
public final class ModelUtil { | ||
private ModelUtil() { | ||
} | ||
|
||
/** | ||
* Gets a list of names (from the name field) from the items in the collection provided. | ||
* For model classes extending {@link NamedIdElement}. | ||
* | ||
* @param collection the collection. | ||
* @return the list of names. | ||
*/ | ||
public static List<String> getNames(Collection<? extends NamedIdElement> collection) { | ||
return collection.stream().map(NamedIdElement::getName).toList(); | ||
} | ||
|
||
/** | ||
* Gets a list of names (from the name field) from the items in the collection provided. | ||
* For model classes extending {@link NamedStringIdElement}. | ||
* | ||
* @param collection the collection. | ||
* @return the list of names. | ||
*/ | ||
public static List<String> getNamesString(Collection<? extends NamedStringIdElement> collection) { | ||
return collection.stream().map(NamedStringIdElement::getName).toList(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.