Skip to content

Commit 5de6205

Browse files
committed
use RawText as source for JsonPath #589
1 parent 211ac74 commit 5de6205

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

webmagic-extension/src/main/java/us/codecraft/webmagic/model/PageModelExtractor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.List;
2020
import java.util.regex.Pattern;
2121

22+
import static us.codecraft.webmagic.model.annotation.ExtractBy.Source.RawText;
23+
2224
/**
2325
* The main internal logic of page model extractor.
2426
*
@@ -125,9 +127,12 @@ private FieldExtractor getAnnotationExtractBy(Class clazz, Field field) {
125127
ExtractBy extractBy = field.getAnnotation(ExtractBy.class);
126128
if (extractBy != null) {
127129
Selector selector = ExtractorUtils.getSelector(extractBy);
128-
130+
ExtractBy.Source source0 = extractBy.source();
131+
if (extractBy.type()== ExtractBy.Type.JsonPath){
132+
source0 = RawText;
133+
}
129134
FieldExtractor.Source source = null;
130-
switch (extractBy.source()){
135+
switch (source0){
131136
case RawText:
132137
source = FieldExtractor.Source.RawText;
133138
break;

webmagic-extension/src/test/java/us/codecraft/webmagic/model/PageModelExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static class ModelCustomList {
7777

7878
public static class ModelJsonStr {
7979

80-
@ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.name",source = ExtractBy.Source.RawText)
80+
@ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.name")
8181
private String name;
8282

8383
}

0 commit comments

Comments
 (0)