-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: minor refactor of the
IntegrationManager
- Loading branch information
Showing
3 changed files
with
70 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dev.jbang.util; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import com.google.gson.TypeAdapter; | ||
import com.google.gson.stream.JsonReader; | ||
import com.google.gson.stream.JsonToken; | ||
import com.google.gson.stream.JsonWriter; | ||
|
||
public class FileTypeAdapter extends TypeAdapter<File> { | ||
@Override | ||
public File read(JsonReader in) throws IOException { | ||
if (in.peek() == JsonToken.NULL) { | ||
in.nextNull(); | ||
return null; | ||
} | ||
String path = in.nextString(); | ||
return new File(path); | ||
} | ||
|
||
@Override | ||
public void write(JsonWriter out, File path) throws IOException { | ||
if (path == null) { | ||
out.nullValue(); | ||
return; | ||
} | ||
out.value(path.getPath()); | ||
} | ||
} |
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,31 @@ | ||
package dev.jbang.util; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import com.google.gson.TypeAdapter; | ||
import com.google.gson.stream.JsonReader; | ||
import com.google.gson.stream.JsonToken; | ||
import com.google.gson.stream.JsonWriter; | ||
|
||
public class PathTypeAdapter extends TypeAdapter<Path> { | ||
@Override | ||
public Path read(JsonReader in) throws IOException { | ||
if (in.peek() == JsonToken.NULL) { | ||
in.nextNull(); | ||
return null; | ||
} | ||
String path = in.nextString(); | ||
return Paths.get(path); | ||
} | ||
|
||
@Override | ||
public void write(JsonWriter out, Path path) throws IOException { | ||
if (path == null) { | ||
out.nullValue(); | ||
return; | ||
} | ||
out.value(path.toString()); | ||
} | ||
} |