Skip to content

Commit

Permalink
fix: JSON nulls were inserted as STRINGs and rejected (#952)
Browse files Browse the repository at this point in the history
Null values for JSON columns were inserted with type STRING, and then
rejected by Cloud Spanner. This change also overrides the setNull
methods, so these also explicitly state that the null value is a JSON.
  • Loading branch information
olavloite authored Mar 8, 2024
1 parent 05211ba commit c7c23a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ protected void doBind(CallableStatement st, X value, String name, WrapperOptions
value, getJavaType(), options);
st.setObject(name, json, JsonType.VENDOR_TYPE_NUMBER);
}

@Override
protected void doBindNull(PreparedStatement st, int index, WrapperOptions options)
throws SQLException {
st.setNull(index, JsonType.VENDOR_TYPE_NUMBER);
}

@Override
protected void doBindNull(CallableStatement st, String name, WrapperOptions options)
throws SQLException {
st.setNull(name, JsonType.VENDOR_TYPE_NUMBER);
}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ public void testSaveVenue() {
}
}

@Test
public void testSaveVenueWithNullDescription() {
try (Session session = sessionFactory.openSession()) {
final Transaction transaction = session.beginTransaction();
Venue venue = new Venue("Venue 2", /* description = */ null);
session.persist(venue);
transaction.commit();

session.refresh(venue);
assertEquals("Venue 2", venue.getName());
assertNull(venue.getDescription());
}
}

@Test
public void testSaveConcert() {
try (Session session = sessionFactory.openSession()) {
Expand Down

0 comments on commit c7c23a1

Please sign in to comment.