diff --git a/firebase-dataconnect/CHANGELOG.md b/firebase-dataconnect/CHANGELOG.md index 8acc4d43026..05d84807aad 100644 --- a/firebase-dataconnect/CHANGELOG.md +++ b/firebase-dataconnect/CHANGELOG.md @@ -23,6 +23,13 @@ * [changed] Replaced java.util.Date with com.google.firebase.dataconnect.LocalDate. ([#6434](https://github.com/firebase/firebase-android-sdk/pull/6434)) +* [changed] `DateSerializer` removed, as it is superceded by + `LocalDateSerializer`. As of Data Connect emulator version 1.7.0, the + generated Kotlin code uses `com.google.firebase.dataconnect.LocalDate` + instead of `java.util.Date`. Therefore, this version of the SDK must be + paired with code generated by version 1.7.0 (or later) of the Data Connect + emulator. + ([#6513](https://github.com/firebase/firebase-android-sdk/pull/6513)) # 16.0.0-beta02 * [changed] Updated protobuf dependency to `3.25.5` to fix diff --git a/firebase-dataconnect/api.txt b/firebase-dataconnect/api.txt index e1ebc29d5b8..11e44aa0dae 100644 --- a/firebase-dataconnect/api.txt +++ b/firebase-dataconnect/api.txt @@ -310,14 +310,6 @@ package com.google.firebase.dataconnect.serializers { field @NonNull public static final com.google.firebase.dataconnect.serializers.AnyValueSerializer INSTANCE; } - public final class DateSerializer implements kotlinx.serialization.KSerializer { - method @NonNull public java.util.Date deserialize(@NonNull kotlinx.serialization.encoding.Decoder decoder); - method @NonNull public kotlinx.serialization.descriptors.SerialDescriptor getDescriptor(); - method public void serialize(@NonNull kotlinx.serialization.encoding.Encoder encoder, @NonNull java.util.Date value); - property @NonNull public kotlinx.serialization.descriptors.SerialDescriptor descriptor; - field @NonNull public static final com.google.firebase.dataconnect.serializers.DateSerializer INSTANCE; - } - public final class LocalDateSerializer implements kotlinx.serialization.KSerializer { method @NonNull public com.google.firebase.dataconnect.LocalDate deserialize(@NonNull kotlinx.serialization.encoding.Decoder decoder); method @NonNull public kotlinx.serialization.descriptors.SerialDescriptor getDescriptor(); diff --git a/firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/serializers/DateSerializer.kt b/firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/serializers/DateSerializer.kt deleted file mode 100644 index 6ff9cb79c13..00000000000 --- a/firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/serializers/DateSerializer.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * 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 com.google.firebase.dataconnect.serializers - -import java.util.Calendar -import java.util.Date -import java.util.GregorianCalendar -import java.util.TimeZone -import java.util.regex.Matcher -import java.util.regex.Pattern -import kotlinx.serialization.KSerializer -import kotlinx.serialization.descriptors.PrimitiveKind -import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder - -/** - * An implementation of [KSerializer] for serializing and deserializing [Date] objects in the wire - * format expected by the Firebase Data Connect backend. - */ -public object DateSerializer : KSerializer { - - override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("Date", PrimitiveKind.STRING) - - override fun serialize(encoder: Encoder, value: Date) { - val calendar = GregorianCalendar(TimeZone.getTimeZone("UTC")) - calendar.time = value - - val year = calendar.get(Calendar.YEAR) - val month = calendar.get(Calendar.MONTH) + 1 - val day = calendar.get(Calendar.DAY_OF_MONTH) - - val serializedDate = - "$year".padStart(4, '0') + '-' + "$month".padStart(2, '0') + '-' + "$day".padStart(2, '0') - encoder.encodeString(serializedDate) - } - - override fun deserialize(decoder: Decoder): Date { - val serializedDate = decoder.decodeString() - - val matcher = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})$").matcher(serializedDate) - require(matcher.matches()) { "date does not match regular expression: ${matcher.pattern()}" } - - fun Matcher.groupToIntIgnoringLeadingZeroes(index: Int): Int { - val groupText = group(index)!!.trimStart('0') - return if (groupText.isEmpty()) 0 else groupText.toInt() - } - - val year = matcher.groupToIntIgnoringLeadingZeroes(1) - val month = matcher.groupToIntIgnoringLeadingZeroes(2) - val day = matcher.groupToIntIgnoringLeadingZeroes(3) - - return GregorianCalendar(TimeZone.getTimeZone("UTC")) - .apply { - set(year, month - 1, day, 0, 0, 0) - set(Calendar.MILLISECOND, 0) - } - .time - } -}