generated from htl-leonding-college/asciidoctor-convert-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from wfee2000/main
Mitschrift vom 2024-01-30
- Loading branch information
Showing
8 changed files
with
207 additions
and
25 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
labs/MyFirstApp/app/src/main/java/at/ac/htl/myfirstapp/model/ModelMapper.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 at.ac.htl.myfirstapp.model; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.CompletionException; | ||
|
||
public class ModelMapper<T> { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
Class<? extends T> classType; | ||
|
||
public ModelMapper(Class<? extends T> classType) { | ||
this.classType = classType; | ||
} | ||
|
||
public byte[] toResource(T model) { | ||
try { | ||
return mapper.writeValueAsBytes(model); | ||
} catch (JsonProcessingException e) { | ||
throw new CompletionException(e); | ||
} | ||
} | ||
|
||
public T fromResource(byte[] bytes) { | ||
try { | ||
return mapper.readValue(bytes, classType); | ||
} catch (IOException e) { | ||
throw new CompletionException(e); | ||
} | ||
} | ||
|
||
public T clone(T model) { | ||
return fromResource(toResource(model)); | ||
} | ||
} |
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