-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclude json-smart transitive dependency by implementing JsonProvider…
… via Moshi
- Loading branch information
Showing
6 changed files
with
95 additions
and
13 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
49 changes: 49 additions & 0 deletions
49
dd-trace-core/src/main/java/datadog/trace/payloadtags/MoshiJsonProvider.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,49 @@ | ||
package datadog.trace.payloadtags; | ||
|
||
import com.jayway.jsonpath.InvalidJsonException; | ||
import com.jayway.jsonpath.spi.json.AbstractJsonProvider; | ||
import com.squareup.moshi.JsonAdapter; | ||
import com.squareup.moshi.Moshi; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.LinkedHashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import okio.BufferedSource; | ||
import okio.Okio; | ||
|
||
public class MoshiJsonProvider extends AbstractJsonProvider { | ||
private final Moshi moshi = new Moshi.Builder().build(); | ||
private final JsonAdapter<Object> jsonAdapter = moshi.adapter(Object.class).lenient(); | ||
|
||
@Override | ||
public Object parse(String s) throws InvalidJsonException { | ||
try { | ||
return jsonAdapter.fromJson(s); | ||
} catch (IOException e) { | ||
throw new InvalidJsonException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public Object parse(InputStream inputStream, String s) throws InvalidJsonException { | ||
try (BufferedSource source = Okio.buffer(Okio.source(inputStream))) { | ||
return jsonAdapter.fromJson(source); | ||
} catch (IOException e) { | ||
throw new InvalidJsonException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public String toJson(Object o) { | ||
return jsonAdapter.toJson(o); | ||
} | ||
|
||
public List<Object> createArray() { | ||
return new LinkedList<>(); | ||
} | ||
|
||
public Object createMap() { | ||
return new LinkedHashMap<>(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
dd-trace-core/src/main/java/datadog/trace/payloadtags/MoshiMappingProvider.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,17 @@ | ||
package datadog.trace.payloadtags; | ||
|
||
import com.jayway.jsonpath.Configuration; | ||
import com.jayway.jsonpath.TypeRef; | ||
import com.jayway.jsonpath.spi.mapper.MappingProvider; | ||
|
||
public class MoshiMappingProvider implements MappingProvider { | ||
@Override | ||
public <T> T map(Object o, Class<T> aClass, Configuration configuration) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> T map(Object o, TypeRef<T> typeRef, Configuration configuration) { | ||
return null; | ||
} | ||
} |
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