Skip to content

Commit 2b0ee7f

Browse files
feat(fossid): Ignore unknown JSON properties
Ensure to stay compatible with non-breaking changes in the FossID API by ignoring unknown JSON properties in FossID responses. This adds the support for FossID version 2025.1.x that added the parameter `projectscan_type` to the `Snippet`. Signed-off-by: Marcel Bochtler <[email protected]>
1 parent 2fd301c commit 2b0ee7f

File tree

8 files changed

+66
-15
lines changed

8 files changed

+66
-15
lines changed

clients/fossid-webapp/src/main/kotlin/EntityResponseBody.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package org.ossreviewtoolkit.clients.fossid
2121

22-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
23-
24-
@JsonIgnoreProperties(ignoreUnknown = true)
2522
class EntityResponseBody<T>(
2623
val operation: String? = null,
2724
val status: Int? = null,

clients/fossid-webapp/src/main/kotlin/FossIdRestService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.core.JsonParser
2525
import com.fasterxml.jackson.core.JsonToken
2626
import com.fasterxml.jackson.databind.BeanProperty
2727
import com.fasterxml.jackson.databind.DeserializationContext
28+
import com.fasterxml.jackson.databind.DeserializationFeature
2829
import com.fasterxml.jackson.databind.JavaType
2930
import com.fasterxml.jackson.databind.JsonDeserializer
3031
import com.fasterxml.jackson.databind.MapperFeature
@@ -80,6 +81,7 @@ interface FossIdRestService {
8081
// FossID has a bug in get_results/scan.
8182
// Sometimes the match_type is "ignored", sometimes it is "Ignored".
8283
enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
84+
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
8385
addModule(
8486
kotlinModule().addDeserializer(PolymorphicList::class.java, PolymorphicListDeserializer())
8587
.addDeserializer(PolymorphicInt::class.java, PolymorphicIntDeserializer())

clients/fossid-webapp/src/main/kotlin/model/Project.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
package org.ossreviewtoolkit.clients.fossid.model
2121

22-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
2322
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
2423

25-
@JsonIgnoreProperties(ignoreUnknown = true)
2624
data class Project(
2725
val id: Int,
2826

clients/fossid-webapp/src/main/kotlin/model/Scan.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
package org.ossreviewtoolkit.clients.fossid.model
2121

22-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
2322
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
2423

25-
@JsonIgnoreProperties(ignoreUnknown = true)
2624
data class Scan(
2725
val id: Int,
2826
val created: String?,

clients/fossid-webapp/src/main/kotlin/model/identification/identifiedFiles/License.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919

2020
package org.ossreviewtoolkit.clients.fossid.model.identification.identifiedFiles
2121

22-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
23-
2422
import org.ossreviewtoolkit.clients.fossid.model.identification.common.LicenseMatchType
2523
import org.ossreviewtoolkit.clients.fossid.model.result.LicenseCategory
2624

27-
@JsonIgnoreProperties(ignoreUnknown = true)
2825
data class License(
2926
val fileLicenseMatchType: LicenseMatchType,
3027

clients/fossid-webapp/src/main/kotlin/model/rules/IgnoreRule.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919

2020
package org.ossreviewtoolkit.clients.fossid.model.rules
2121

22-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
23-
2422
/**
2523
* An "ignore rule" allows specifying FossID which files need to be excluded from scan.
2624
*/
27-
@JsonIgnoreProperties(ignoreUnknown = true)
2825
data class IgnoreRule(
2926
/**
3027
* The id of the rule.

clients/fossid-webapp/src/main/kotlin/model/status/ScanDescription2021dot2.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919

2020
package org.ossreviewtoolkit.clients.fossid.model.status
2121

22-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
2322
import com.fasterxml.jackson.annotation.JsonProperty
2423

2524
/**
2625
* A description of scan status. This class is for FossID version 2021.2 and later.
2726
*/
28-
@JsonIgnoreProperties(ignoreUnknown = true)
2927
data class ScanDescription2021dot2(
3028
val id: Long?,
3129
val scanId: String,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (C) 2025 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.ossreviewtoolkit.clients.fossid
21+
22+
import com.fasterxml.jackson.module.kotlin.readValue
23+
24+
import io.kotest.core.spec.style.StringSpec
25+
26+
import org.ossreviewtoolkit.clients.fossid.model.result.Snippet
27+
28+
class FossId2025dot1Test : StringSpec({
29+
"Snippet model can be deserialized" {
30+
val responseJson = """
31+
{
32+
"id": "30",
33+
"created": "2025-10-14 14:31:10",
34+
"scan_id": "49",
35+
"scan_file_id": "112254",
36+
"file_id": "63380",
37+
"match_type": "partial",
38+
"reason": "",
39+
"author": "someAuthor",
40+
"artifact": "adbc",
41+
"version": "0.2.4-rc0",
42+
"purl": "pkg:github/aaa/[email protected]",
43+
"artifact_license": "Apache-2.0",
44+
"artifact_license_category": "PERMISSIVE",
45+
"release_date": "2024-03-29 00:00:00",
46+
"mirror": "asdf123aaaaa",
47+
"file": "3rd_party/example/CONTRIBUTING.md",
48+
"file_license": "Apache-2.0",
49+
"url": "https://github.com/oss-review-toolkit/example/archive/v0.2.4-rc0.tar.gz",
50+
"hits": "10 (100%)",
51+
"size": "13249",
52+
"updated": "2025-10-14 14:31:10",
53+
"cpe": null,
54+
"score": "1",
55+
"match_file_id": "cae2442400f7293382f118cb00000000",
56+
"classification": null,
57+
"highlighting": "",
58+
"projectscan_type": ""
59+
}
60+
""".trimIndent()
61+
62+
FossIdRestService.JSON_MAPPER.readValue<Snippet>(responseJson)
63+
}
64+
})

0 commit comments

Comments
 (0)