File tree 3 files changed +28
-0
lines changed
core/src/commonMain/kotlin/nl/adaptivity/xmlutil
serialization/src/commonTest/kotlin/nl/adaptivity/xml/serialization
3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -348,6 +348,7 @@ fun XmlReader.readSimpleElement(): String {
348
348
EventType .PROCESSING_INSTRUCTION -> {
349
349
}
350
350
EventType .TEXT ,
351
+ EventType .ENTITY_REF ,
351
352
EventType .CDSECT -> append(t.text)
352
353
else -> throw XmlException (
353
354
" Expected text content or end tag, found: ${t.eventType} "
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ package nl.adaptivity.xml.serialization
25
25
import kotlinx.serialization.ExperimentalSerializationApi
26
26
import kotlinx.serialization.KSerializer
27
27
import kotlinx.serialization.SerializationException
28
+ import kotlinx.serialization.decodeFromString
28
29
import kotlinx.serialization.json.Json
29
30
import kotlinx.serialization.json.JsonBuilder
30
31
import kotlinx.serialization.modules.EmptySerializersModule
@@ -680,4 +681,23 @@ class TestCommon {
680
681
assertEquals(contentText, serialized)
681
682
}
682
683
684
+
685
+ @Test
686
+ fun deserializeXmlWithEntity () {
687
+ val xml = XML {
688
+ repairNamespaces = true
689
+ policy = DefaultXmlSerializationPolicy (pedantic = false , autoPolymorphic = false )
690
+ }
691
+
692
+ val expected = StringWithMarkup (" Chloroacetic acid, >=99%" )
693
+
694
+ val actual = xml.decodeFromString<StringWithMarkup >(
695
+ " <StringWithMarkup xmlns=\" http://pubchem.ncbi.nlm.nih.gov/pug_view\" >\n " +
696
+ " <String>Chloroacetic acid, >=99%</String>\n " +
697
+ " </StringWithMarkup>"
698
+ )
699
+ assertEquals(expected, actual)
700
+ }
701
+
702
+
683
703
}
Original file line number Diff line number Diff line change @@ -374,3 +374,10 @@ internal data class Tag(
374
374
}
375
375
376
376
}
377
+
378
+ @XmlSerialName(" StringWithMarkup" , " http://pubchem.ncbi.nlm.nih.gov/pug_view" , " " )
379
+ @Serializable
380
+ data class StringWithMarkup (
381
+ @XmlElement(true ) @SerialName(" String" ) val string : String = " " ,
382
+ val markup : List <String > = emptyList()
383
+ )
You can’t perform that action at this time.
0 commit comments