-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #331 - Gson error when merging reports due to Throwable#detailM…
…essage
- Loading branch information
1 parent
36c7418
commit 8c67fcc
Showing
14 changed files
with
247 additions
and
89 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
16 changes: 0 additions & 16 deletions
16
src/main/java/com/aventstack/extentreports/gson/BddTypeAdapterFactory.java
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/aventstack/extentreports/gson/GsonTypeAdapterFactory.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,22 @@ | ||
package com.aventstack.extentreports.gson; | ||
|
||
import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel; | ||
import com.google.gson.Gson; | ||
import com.google.gson.TypeAdapter; | ||
import com.google.gson.TypeAdapterFactory; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
public class GsonTypeAdapterFactory implements TypeAdapterFactory { | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { | ||
if (Class.class.isAssignableFrom(type.getRawType()) && | ||
type.getType().getTypeName().indexOf(IGherkinFormatterModel.class.getTypeName()) >= 0) { | ||
return (TypeAdapter<T>) new BddTypeAdapter(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/aventstack/extentreports/gson/ThrowableTypeAdapter.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,38 @@ | ||
package com.aventstack.extentreports.gson; | ||
|
||
import com.google.gson.TypeAdapter; | ||
import com.google.gson.stream.JsonReader; | ||
import com.google.gson.stream.JsonWriter; | ||
|
||
import java.io.IOException; | ||
|
||
public class ThrowableTypeAdapter extends TypeAdapter<Throwable> { | ||
|
||
@Override | ||
public Throwable read(final JsonReader reader) { | ||
return new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void write(final JsonWriter out, final Throwable value) throws IOException { | ||
if (value == null) { | ||
out.nullValue(); | ||
return; | ||
} | ||
|
||
out.beginObject(); | ||
out.name("type"); | ||
out.value(value.getClass().getSimpleName()); | ||
|
||
out.name("message"); | ||
out.value(value.getMessage()); | ||
|
||
final Throwable cause = value.getCause(); | ||
if (cause != null) { | ||
out.name("cause"); | ||
write(out, cause); | ||
} | ||
|
||
out.endObject(); | ||
} | ||
} |
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
Oops, something went wrong.