Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public RoutingType read(JsonReader in) throws IOException {
throw new AssertionFailure( "Unexpected property for attribute of type " + RoutingType.class + ": " + name );
}
}
in.endObject();

return value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.backend.elasticsearch.gson.spi;

import static org.assertj.core.api.Assertions.assertThatCode;

import org.hibernate.search.backend.elasticsearch.lowlevel.index.mapping.impl.RootTypeMapping;
import org.hibernate.search.util.impl.test.JsonHelper;
import org.hibernate.search.util.impl.test.annotation.TestForIssue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

@RunWith(Parameterized.class)
@TestForIssue(jiraKey = "HSEARCH-4580")
public class GsonParsingTest {

@Parameterized.Parameters
public static Object[][] params() {
return new Object[][] {
{ "{\"_routing\": {\"required\": true}}", RootTypeMapping.class } // HSEARCH-4580
};
}

private final Gson gson;

@Parameterized.Parameter(0)
public String jsonToParse;
@Parameterized.Parameter(1)
public Class<?> targetType;

public GsonParsingTest() {
gson = GsonProvider.create( GsonBuilder::new, true ).getGsonNoSerializeNulls();
}

@Test
public void parsingWithoutException() {
assertThatCode( () -> gson.fromJson( jsonToParse, targetType ) ).doesNotThrowAnyException();
}

@Test
public void noInformationLoss() {
Object parsed = gson.fromJson( jsonToParse, targetType );
String written = gson.toJson( parsed );
JsonHelper.assertJsonEquals( jsonToParse, written );
}
}