This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reports: use ExclusionStrategy when serializing command reports.
This exclusion strategy makes sure to skip serialization of any classes implementing the WebDriver interface. Since this object is redundant when reporting command parameters and doesn’t pass serialization - we exclude it. See google/gson#1540 for more details on the serialization problem. (edited) Signed-off-by: Gil Eliyahu <gil.eliyahu@testproject.io>
- Loading branch information
1 parent
d8f2891
commit 7cbfe36
Showing
3 changed files
with
78 additions
and
1 deletion.
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
55 changes: 55 additions & 0 deletions
55
src/main/java/io/testproject/sdk/internal/rest/serialization/DriverExclusionStrategy.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,55 @@ | ||
/* | ||
* Copyright (c) 2020 TestProject LTD. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.testproject.sdk.internal.rest.serialization; | ||
|
||
import com.google.gson.ExclusionStrategy; | ||
import com.google.gson.FieldAttributes; | ||
import org.openqa.selenium.WebDriver; | ||
|
||
/** | ||
* This exclusion strategy makes sure to skip serialization of any classes implementing the WebDriver interface. | ||
* Since this object is redundant when reporting command parameters and doesn’t pass serialization - we exclude it. | ||
* See https://github.com/google/gson/issues/1540 for more details on the serialization problem | ||
*/ | ||
public class DriverExclusionStrategy implements ExclusionStrategy { | ||
|
||
|
||
/** | ||
* Determines whether the class implements a {@link WebDriver} interface and should be ignored. | ||
* | ||
* @param clazz the class object that is under test | ||
* @return true if the class should be ignored; otherwise false | ||
*/ | ||
@Override | ||
public boolean shouldSkipClass(final Class<?> clazz) { | ||
return WebDriver.class.isAssignableFrom(clazz); | ||
} | ||
|
||
/** | ||
* Determined whether a filed should be skipped. | ||
* It has no effect in this exclusion strategy as there is no need for it. | ||
* Note: It is not used / implemented in this strategy as it is redundant. | ||
* | ||
* @param f the field object that is under test | ||
* @return true if the field should be ignored; otherwise false | ||
*/ | ||
@Override | ||
public boolean shouldSkipField(final FieldAttributes f) { | ||
return false; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/io/testproject/sdk/internal/rest/serialization/package-info.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,21 @@ | ||
/* | ||
* Copyright (c) 2020 TestProject LTD. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Serialization utility classes. | ||
*/ | ||
package io.testproject.sdk.internal.rest.serialization; |