-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
ebean-test/src/test/java/org/tests/json/TestDbJsonLength.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,52 @@ | ||
package org.tests.json; | ||
|
||
import io.ebean.DB; | ||
import io.ebean.DataIntegrityException; | ||
import org.assertj.core.api.SoftAssertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.tests.model.json.EBasicJsonMap; | ||
|
||
import java.util.Map; | ||
|
||
class TestDbJsonLength { | ||
|
||
|
||
/** | ||
* The property 'EBasicJsonMap.content' is annotated with @DbJson(length=5000). So we assume, that we cannot save Json-objects | ||
* where the serialized form exceed that limit and we would expect an error on save. | ||
* The length check works for platforms like h2, as H2 uses a 'varchar(5000)'. So it is impossible to save such long jsons, | ||
* but it won't work for SqlServer, as here 'nvarchar(max)' is used. No validation happens at DB level and you might get very | ||
* large Json objects in your database. This mostly happens unintentionally (programming error, misconfiguration) | ||
* So they are in the database and they cannot be accessed by ebean any more, because there are new limits in Jackson: | ||
* - Max 5 Meg per string in 2.15.0 | ||
* - Max 20 Meg per string in 2.15.1 | ||
* see https://github.com/FasterXML/jackson-core/issues/1014 | ||
*/ | ||
@Test | ||
void testLongString() { | ||
// s is so big, that it could not be deserialized by jackson | ||
String s = new String(new char[20_000_001]).replace('\0', 'x'); | ||
|
||
EBasicJsonMap bean = new EBasicJsonMap(); | ||
bean.setName("b1"); | ||
bean.setContent(Map.of("string", s)); | ||
|
||
SoftAssertions softly = new SoftAssertions(); | ||
|
||
softly.assertThatThrownBy(() -> { | ||
DB.save(bean); | ||
}).isInstanceOf(DataIntegrityException.class); | ||
|
||
|
||
if (bean.getId() != null) { | ||
// we expect, that we could NOT save the bean, but this is not true for sqlServer. | ||
// we will get a javax.persistence.PersistenceException: Error loading on org.tests.model.json.EBasicJsonMap.content | ||
// when we try to load the bean back from DB | ||
DB.find(EBasicJsonMap.class, bean.getId()); | ||
} | ||
|
||
softly.assertAll(); | ||
|
||
} | ||
|
||
} |
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