diff --git a/api/src/org/labkey/api/assay/AssayProtocolSchema.java b/api/src/org/labkey/api/assay/AssayProtocolSchema.java index 705b9ce143e..a2a466079a5 100644 --- a/api/src/org/labkey/api/assay/AssayProtocolSchema.java +++ b/api/src/org/labkey/api/assay/AssayProtocolSchema.java @@ -85,6 +85,7 @@ import org.labkey.api.util.FileUtil; import org.labkey.api.util.HtmlString; import org.labkey.api.util.HtmlStringBuilder; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.PageFlowUtil; import org.labkey.api.util.Path; import org.labkey.api.util.StringExpressionFactory; @@ -913,7 +914,7 @@ public HtmlString getFormattedHtml(RenderContext ctx) try { - Map decodedVals = new ObjectMapper().readValue(val.toString(), Map.class); + Map decodedVals = JsonUtil.DEFAULT_MAPPER.readValue(val.toString(), Map.class); HtmlStringBuilder sb = HtmlStringBuilder.of(decodedVals.remove(ParticipantVisitResolverType.Serializer.STRING_VALUE_PROPERTY_NAME)); // Issue 21126 If lookup was pasted tsv, could still get a default list entry in properties list. Fix the redisplay diff --git a/api/src/org/labkey/api/data/JsonPrettyPrintDisplayColumnFactory.java b/api/src/org/labkey/api/data/JsonPrettyPrintDisplayColumnFactory.java index 09e2292ea4c..ffed06ad1c5 100644 --- a/api/src/org/labkey/api/data/JsonPrettyPrintDisplayColumnFactory.java +++ b/api/src/org/labkey/api/data/JsonPrettyPrintDisplayColumnFactory.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.jetbrains.annotations.NotNull; import org.labkey.api.util.HtmlString; +import org.labkey.api.util.JsonUtil; import java.io.IOException; @@ -51,7 +52,7 @@ public HtmlString getFormattedHtml(RenderContext ctx) if (null == value) return HtmlString.EMPTY_STRING; - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = JsonUtil.createDefaultMapper(); DefaultPrettyPrinter pp = new DefaultPrettyPrinter(); pp.indentArraysWith(new DefaultIndenter()); diff --git a/api/src/org/labkey/api/data/JsonTest.java b/api/src/org/labkey/api/data/JsonTest.java index d1e1378eb42..4bcfc6a099e 100644 --- a/api/src/org/labkey/api/data/JsonTest.java +++ b/api/src/org/labkey/api/data/JsonTest.java @@ -75,7 +75,7 @@ public void jacksonTest() { try { - ObjectMapper mapper = new ObjectMapper().setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + ObjectMapper mapper = JsonUtil.createDefaultMapper().setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); Customer roundTripC1 = mapper.readValue(mapper.writeValueAsString(c1), Customer.class); assertEquals(c1, roundTripC1); Customer roundTripC2 = mapper.readValue(mapper.writeValueAsString(c2), Customer.class); diff --git a/api/src/org/labkey/api/exp/TemplateInfo.java b/api/src/org/labkey/api/exp/TemplateInfo.java index bbde4e0c44b..884e3a473a0 100644 --- a/api/src/org/labkey/api/exp/TemplateInfo.java +++ b/api/src/org/labkey/api/exp/TemplateInfo.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; import org.labkey.api.data.JdbcType; +import org.labkey.api.util.JsonUtil; import java.io.IOException; import java.io.StringWriter; @@ -73,7 +74,7 @@ public String toJSON() { StringWriter sw = new StringWriter(); JsonGenerator jsonGen = new JsonFactory().createGenerator(sw); - jsonGen.setCodec(new ObjectMapper()); + jsonGen.setCodec(JsonUtil.createDefaultMapper()); jsonGen.writeObject(this); return sw.toString(); } @@ -90,8 +91,7 @@ public static TemplateInfo fromJson(String json) try { - ObjectMapper om = new ObjectMapper(); - HashMap map = om.readValue(json, HashMap.class); + HashMap map = JsonUtil.DEFAULT_MAPPER.readValue(json, HashMap.class); Double createdModuleVersion = null; if (null != map.get("createdModuleVersion")) createdModuleVersion = (Double) JdbcType.DOUBLE.convert(map.get("createdModuleVersion")); diff --git a/api/src/org/labkey/api/exp/api/DomainKindDesign.java b/api/src/org/labkey/api/exp/api/DomainKindDesign.java index 64b8d94a28b..64d304762a2 100644 --- a/api/src/org/labkey/api/exp/api/DomainKindDesign.java +++ b/api/src/org/labkey/api/exp/api/DomainKindDesign.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.labkey.api.gwt.client.model.GWTDomain; +import org.labkey.api.util.JsonUtil; import java.util.Map; @@ -23,8 +24,7 @@ public void setDomainDesign(GWTDomain domainDesign) public Map getOptions() { - ObjectMapper mapper = new ObjectMapper(); - return mapper.convertValue(_options, Map.class); + return JsonUtil.DEFAULT_MAPPER.convertValue(_options, Map.class); } public void setOptions(T options) diff --git a/api/src/org/labkey/api/exp/api/ExperimentJSONConverter.java b/api/src/org/labkey/api/exp/api/ExperimentJSONConverter.java index d590bd05908..1882e8dab90 100644 --- a/api/src/org/labkey/api/exp/api/ExperimentJSONConverter.java +++ b/api/src/org/labkey/api/exp/api/ExperimentJSONConverter.java @@ -47,6 +47,7 @@ import org.labkey.api.query.ValidationException; import org.labkey.api.security.User; import org.labkey.api.security.permissions.ReadPermission; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.Pair; import org.labkey.api.util.URIUtil; @@ -895,8 +896,7 @@ public static String getAliasJson(Map importAliases, String curr try { - ObjectMapper mapper = new ObjectMapper(); - return mapper.writeValueAsString(aliases); + return JsonUtil.DEFAULT_MAPPER.writeValueAsString(aliases); } catch (JsonProcessingException e) { diff --git a/api/src/org/labkey/api/exp/property/DomainUtil.java b/api/src/org/labkey/api/exp/property/DomainUtil.java index 486a85ace5f..a13b451ec2d 100644 --- a/api/src/org/labkey/api/exp/property/DomainUtil.java +++ b/api/src/org/labkey/api/exp/property/DomainUtil.java @@ -73,6 +73,7 @@ import org.labkey.api.util.DateUtil; import org.labkey.api.util.GUID; import org.labkey.api.util.JdbcUtil; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.Pair; import org.labkey.api.util.StringExpression; import org.labkey.api.view.UnauthorizedException; @@ -132,7 +133,7 @@ else if (AbstractAssayProvider.PARTICIPANT_VISIT_RESOLVER_PROPERTY_NAME.equalsIg // addition nested properties containing ThawList list settings. try { - Map decodedVals = new ObjectMapper().readValue(defaultValue.toString(), Map.class); + Map decodedVals = JsonUtil.DEFAULT_MAPPER.readValue(defaultValue.toString(), Map.class); String stringValue = decodedVals.get("stringValue"); if (stringValue != null) return stringValue; @@ -640,10 +641,9 @@ public static Domain createDomain( { throw new ValidationException(ve); } - ObjectMapper mapper = new ObjectMapper(); arguments = kind.processArguments(container, user, arguments); - Object options = mapper.convertValue(arguments, kind.getTypeClass()); + Object options = JsonUtil.DEFAULT_MAPPER.convertValue(arguments, kind.getTypeClass()); Domain created = kind.createDomain(domain, options, container, user, templateInfo); if (created == null) diff --git a/api/src/org/labkey/api/files/view/filesWebPart.jsp b/api/src/org/labkey/api/files/view/filesWebPart.jsp index a7149c0f218..b7ca9f94f53 100644 --- a/api/src/org/labkey/api/files/view/filesWebPart.jsp +++ b/api/src/org/labkey/api/files/view/filesWebPart.jsp @@ -77,7 +77,7 @@
diff --git a/api/src/org/labkey/api/util/JavaScriptFragment.java b/api/src/org/labkey/api/util/JavaScriptFragment.java index da9a5413d1a..2037f43455f 100644 --- a/api/src/org/labkey/api/util/JavaScriptFragment.java +++ b/api/src/org/labkey/api/util/JavaScriptFragment.java @@ -1,5 +1,7 @@ package org.labkey.api.util; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,6 +11,7 @@ */ public class JavaScriptFragment implements SafeToRender { + public static final JavaScriptFragment EMPTY = new JavaScriptFragment(""); public static final JavaScriptFragment EMPTY_STRING = JavaScriptFragment.unsafe("''"); public static final JavaScriptFragment NULL = JavaScriptFragment.unsafe(" null "); public static final JavaScriptFragment TRUE = JavaScriptFragment.unsafe(" true "); @@ -25,9 +28,42 @@ public class JavaScriptFragment implements SafeToRender */ public static @NotNull JavaScriptFragment unsafe(@Nullable String s) { + if (null == s) + return EMPTY; + // even with unsafe() a javascript fragment can never contain the sequence "" + // since metrics) if (metrics.size() > 0) { String serializedMetrics; - ObjectMapper mapper = new ObjectMapper(); try { - serializedMetrics = mapper.writeValueAsString(metrics); + serializedMetrics = JsonUtil.DEFAULT_MAPPER.writeValueAsString(metrics); addParam(JSON_METRICS_KEY, serializedMetrics); } catch (JsonProcessingException e) diff --git a/api/src/org/labkey/api/util/SafeToRenderBuilder.java b/api/src/org/labkey/api/util/SafeToRenderBuilder.java index 7554f0aa30a..8574790f438 100644 --- a/api/src/org/labkey/api/util/SafeToRenderBuilder.java +++ b/api/src/org/labkey/api/util/SafeToRenderBuilder.java @@ -32,7 +32,7 @@ public int length() public SafeToRender getSafeToRender() { - return JavaScriptFragment.unsafe(_sb.toString()); + return HtmlString.unsafe(_sb.toString()); } @Override diff --git a/api/src/org/labkey/api/util/UsageReportingLevel.java b/api/src/org/labkey/api/util/UsageReportingLevel.java index 574ec1f6682..b993968a509 100644 --- a/api/src/org/labkey/api/util/UsageReportingLevel.java +++ b/api/src/org/labkey/api/util/UsageReportingLevel.java @@ -334,7 +334,7 @@ public static Map getMetrics(UsageReportingLevel level) try { @SuppressWarnings({"unchecked"}) - Map metrics = new ObjectMapper().readValue(Objects.requireNonNull(getReportParams(level)).get("jsonMetrics"), Map.class); + Map metrics = JsonUtil.DEFAULT_MAPPER.readValue(Objects.requireNonNull(getReportParams(level)).get("jsonMetrics"), Map.class); return metrics; } catch (IOException e) diff --git a/assay/src/org/labkey/assay/plate/AssayPlateMetadataServiceImpl.java b/assay/src/org/labkey/assay/plate/AssayPlateMetadataServiceImpl.java index 7b118ec8156..998e06e812d 100644 --- a/assay/src/org/labkey/assay/plate/AssayPlateMetadataServiceImpl.java +++ b/assay/src/org/labkey/assay/plate/AssayPlateMetadataServiceImpl.java @@ -44,6 +44,7 @@ import org.labkey.api.query.QueryUpdateService; import org.labkey.api.query.ValidationException; import org.labkey.api.security.User; +import org.labkey.api.util.JsonUtil; import org.labkey.assay.TSVProtocolSchema; import org.labkey.assay.plate.model.Well; import org.labkey.assay.query.AssayDbSchema; @@ -412,11 +413,10 @@ public Map parsePlateMetadata(JSONObject json) throws Exp { try { - ObjectMapper mapper = new ObjectMapper(); if (json == null) throw new ExperimentException("No plate metadata was uploaded"); - return _parsePlateMetadata(mapper.readTree(json.toString())); + return _parsePlateMetadata(JsonUtil.DEFAULT_MAPPER.readTree(json.toString())); } catch (Exception e) { @@ -429,11 +429,10 @@ public Map parsePlateMetadata(File jsonData) throws Exper { try { - ObjectMapper mapper = new ObjectMapper(); if (jsonData == null) throw new ExperimentException("No plate metadata was uploaded"); - return _parsePlateMetadata(mapper.readTree(jsonData)); + return _parsePlateMetadata(JsonUtil.DEFAULT_MAPPER.readTree(jsonData)); } catch (Exception e) { diff --git a/core/src/org/labkey/core/admin/createFolder.jsp b/core/src/org/labkey/core/admin/createFolder.jsp index 15ad921d2c6..2b7465e023f 100644 --- a/core/src/org/labkey/core/admin/createFolder.jsp +++ b/core/src/org/labkey/core/admin/createFolder.jsp @@ -24,6 +24,7 @@ <%@ page import="org.labkey.core.admin.AdminController" %> <%@ page import="org.labkey.core.portal.CollaborationFolderType" %> <%@ page import="org.labkey.core.portal.ProjectController" %> +<%@ page import="org.labkey.api.util.JavaScriptFragment" %> <%@ page extends="org.labkey.api.jsp.JspBase" %> <%! @Override @@ -82,7 +83,7 @@ var moduleTypesMap = {}; var templateFolders = []; var selectedModules = <%=modulesOut%>; - var hasLoaded = <%=text(form.getHasLoaded()?"true":"false")%>; + var hasLoaded = <%=JavaScriptFragment.bool(form.getHasLoaded())%>; var defaultTab = <%=q(form.getDefaultModule())%>; var selectedTemplateFolder = <%=q(form.getTemplateSourceId())%>; var selectedTemplateWriters = <%=templateWriterTypes%>; diff --git a/core/src/org/labkey/core/admin/folderType.jsp b/core/src/org/labkey/core/admin/folderType.jsp index dd05419a36f..1833180dda1 100644 --- a/core/src/org/labkey/core/admin/folderType.jsp +++ b/core/src/org/labkey/core/admin/folderType.jsp @@ -347,7 +347,7 @@ for (Module module : allModules) LABKEY.requiresExt4Sandbox(function() { Ext4.onReady(function() { Ext4.create('Ext.button.Button', { - text: '<%=text(form.isWizard() ? "Next" : "Update Folder")%>', + text: <%=q(form.isWizard() ? "Next" : "Update Folder")%>, renderTo: 'UpdateFolderButtonDiv', handler: function() { if (!validate()) { @@ -380,7 +380,7 @@ for (Module module : allModules) url: LABKEY.ActionURL.buildURL('core', 'getContainerInfo.api'), method: 'POST', jsonData: { - containerPath: "<%=text(path)%>", + containerPath: <%=q(path)%>, newFolderType: newFolderType }, success: function (resp) { diff --git a/core/src/org/labkey/core/admin/moveFolder.jsp b/core/src/org/labkey/core/admin/moveFolder.jsp index 7a99219d907..f0b95ba2c65 100644 --- a/core/src/org/labkey/core/admin/moveFolder.jsp +++ b/core/src/org/labkey/core/admin/moveFolder.jsp @@ -26,6 +26,7 @@ <%@ page import="org.labkey.core.admin.AdminController.MoveFolderTreeView" %> <%@ page import="org.springframework.validation.Errors" %> <%@ page import="org.springframework.validation.ObjectError" %> +<%@ page import="org.labkey.api.util.JavaScriptFragment" %> <%@ page extends="org.labkey.api.jsp.JspBase" %> <%! @Override @@ -113,7 +114,7 @@ editable : true, expandable : true, text : <%=q(project.getParent().getName())%>, - <%=text(project.equals(c) ? "cls : 'x-tree-node-current'" : "")%> + <%=JavaScriptFragment.unsafe(project.equals(c) ? "cls : 'x-tree-node-current'" : "")%> }), rootVisible: false, enableDrag: false, diff --git a/core/src/org/labkey/core/view/configReportsAndScripts.jsp b/core/src/org/labkey/core/view/configReportsAndScripts.jsp index 2b32a6ebc0d..9730962dbe9 100644 --- a/core/src/org/labkey/core/view/configReportsAndScripts.jsp +++ b/core/src/org/labkey/core/view/configReportsAndScripts.jsp @@ -817,7 +817,7 @@ var record = { name: R_ENGINE_NAME, extensions: R_EXTENSIONS, - exeCommand: '<%=text(RReport.DEFAULT_R_CMD)%>', + exeCommand: <%=q(RReport.DEFAULT_R_CMD)%>, <% if (!StringUtils.isEmpty(RReport.getDefaultRPath())) { %> exePath: <%=q(RReport.getDefaultRPath())%>, <% } %> @@ -851,9 +851,9 @@ var record = { name: REMOTE_R_ENGINE_NAME, extensions: R_EXTENSIONS, - machine: '<%=text(RReport.DEFAULT_R_MACHINE)%>', + machine: <%=q(RReport.DEFAULT_R_MACHINE)%>, port:<%=RReport.DEFAULT_R_PORT%>, - exeCommand: '<%=text(RReport.DEFAULT_RSERVE_CMD)%>', + exeCommand: <%=q(RReport.DEFAULT_RSERVE_CMD)%>, outputFileName: <%= q(ExternalScriptEngine.SCRIPT_NAME_REPLACEMENT + ".Rout") %>, 'default': !defaultR, external: true, diff --git a/core/src/org/labkey/core/webdav/davListing.jsp b/core/src/org/labkey/core/webdav/davListing.jsp index 85c31bf3286..ca2733a7b1d 100644 --- a/core/src/org/labkey/core/webdav/davListing.jsp +++ b/core/src/org/labkey/core/webdav/davListing.jsp @@ -23,6 +23,7 @@ <%@ page import="org.labkey.core.webdav.DavController" %> <%@ page import="org.labkey.api.premium.PremiumService" %> <%@ page import="org.apache.commons.lang3.StringUtils" %> +<%@ page import="org.labkey.api.util.JavaScriptFragment" %> <%@ page extends="org.labkey.api.jsp.JspBase" %> <%! @Override @@ -102,7 +103,7 @@ actions: [ 'folderTreeToggle', 'parentFolder', 'refresh', 'createDirectory', 'download', 'deletePath', 'renamePath', 'movePath', 'upload', - '->', htmlViewAction, <%=unsafe(getUser().isGuest() ? "loginAction" : "logoutAction")%> + '->', htmlViewAction, <%=JavaScriptFragment.unsafe(getUser().isGuest() ? "loginAction" : "logoutAction")%> ], useServerActions: false }], diff --git a/experiment/src/org/labkey/experiment/ConfirmDelete.jsp b/experiment/src/org/labkey/experiment/ConfirmDelete.jsp index 39a951093b2..4f0aaa2b8e4 100644 --- a/experiment/src/org/labkey/experiment/ConfirmDelete.jsp +++ b/experiment/src/org/labkey/experiment/ConfirmDelete.jsp @@ -73,7 +73,7 @@ <% if (bean.getObjects().isEmpty()) { %>

There are no <%= h(numReferencedItems > 0 ? " additional " : "")%>selected objects to delete.

- <%= text(button("OK").href(successUrl).toString())%><% + <%= button("OK").href(successUrl) %><% } else { %> @@ -217,6 +217,6 @@ else { %> <%= button("Confirm Delete").submit(true).disableOnClick(true) %> <% } %> - <%= text(button("Cancel").href(cancelUrl).toString())%> + <%= button("Cancel").href(cancelUrl) %> <% } %> diff --git a/experiment/src/org/labkey/experiment/api/ExpDataClassImpl.java b/experiment/src/org/labkey/experiment/api/ExpDataClassImpl.java index b4f6e548a29..93416ab5ea4 100644 --- a/experiment/src/org/labkey/experiment/api/ExpDataClassImpl.java +++ b/experiment/src/org/labkey/experiment/api/ExpDataClassImpl.java @@ -51,6 +51,7 @@ import org.labkey.api.security.User; import org.labkey.api.security.permissions.DataClassReadPermission; import org.labkey.api.security.permissions.MediaReadPermission; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.PageFlowUtil; import org.labkey.api.util.Path; import org.labkey.api.util.UnexpectedException; @@ -321,6 +322,8 @@ public void delete(User user, @Nullable String auditUserComment) public TableInfo getTinfo() { Domain d = getDomain(); + if (null == d) + throw new NullPointerException("domain is null"); return StorageProvisioner.createTableInfo(d); } @@ -505,10 +508,9 @@ public void ensureMinGenId(long newSeqValue, Container c) throws ExperimentExcep try { - ObjectMapper mapper = new ObjectMapper(); TypeReference> typeRef = new TypeReference<>() {}; - return mapper.readValue(ds.getDataParentImportAliasMap(), typeRef); + return JsonUtil.DEFAULT_MAPPER.readValue(ds.getDataParentImportAliasMap(), typeRef); } catch (IOException e) { diff --git a/experiment/src/org/labkey/experiment/api/ExpSampleTypeImpl.java b/experiment/src/org/labkey/experiment/api/ExpSampleTypeImpl.java index 1af6c1dd16f..050b080d429 100644 --- a/experiment/src/org/labkey/experiment/api/ExpSampleTypeImpl.java +++ b/experiment/src/org/labkey/experiment/api/ExpSampleTypeImpl.java @@ -64,6 +64,7 @@ import org.labkey.api.security.User; import org.labkey.api.security.permissions.MediaReadPermission; import org.labkey.api.study.StudyService; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.PageFlowUtil; import org.labkey.api.util.Path; import org.labkey.api.util.StringExpressionFactory; @@ -1005,10 +1006,9 @@ public String getDocumentId() try { - ObjectMapper mapper = new ObjectMapper(); TypeReference> typeRef = new TypeReference<>() {}; - return mapper.readValue(ms.getMaterialParentImportAliasMap(), typeRef); + return JsonUtil.DEFAULT_MAPPER.readValue(ms.getMaterialParentImportAliasMap(), typeRef); } catch (IOException e) { diff --git a/experiment/src/org/labkey/experiment/api/ImportAliasesDisplayColumnFactory.java b/experiment/src/org/labkey/experiment/api/ImportAliasesDisplayColumnFactory.java index 7cd9d2e4951..27c82a6b852 100644 --- a/experiment/src/org/labkey/experiment/api/ImportAliasesDisplayColumnFactory.java +++ b/experiment/src/org/labkey/experiment/api/ImportAliasesDisplayColumnFactory.java @@ -14,6 +14,7 @@ import org.labkey.api.exp.api.ExpSampleType; import org.labkey.api.exp.api.SampleTypeService; import org.labkey.api.util.HtmlString; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.PageFlowUtil; import java.io.IOException; @@ -107,12 +108,11 @@ public HtmlString getFormattedHtml(RenderContext ctx) if (null == value) return HtmlString.EMPTY_STRING; - ObjectMapper mapper = new ObjectMapper(); DefaultPrettyPrinter pp = new DefaultPrettyPrinter(); pp.indentArraysWith(new DefaultIndenter()); - Object json = mapper.readValue(value.toString(), Object.class); - String strValue = mapper.writer(pp).writeValueAsString(json); + Object json = JsonUtil.DEFAULT_MAPPER.readValue(value.toString(), Object.class); + String strValue = JsonUtil.DEFAULT_MAPPER.writer(pp).writeValueAsString(json); String filteredValue = PageFlowUtil.filter(strValue, true); return HtmlString.unsafe("
" + filteredValue + "
"); } diff --git a/experiment/src/org/labkey/experiment/controllers/property/PropertyController.java b/experiment/src/org/labkey/experiment/controllers/property/PropertyController.java index 8566fe475fd..9c5b3717153 100644 --- a/experiment/src/org/labkey/experiment/controllers/property/PropertyController.java +++ b/experiment/src/org/labkey/experiment/controllers/property/PropertyController.java @@ -90,6 +90,7 @@ import org.labkey.api.util.ExceptionUtil; import org.labkey.api.util.FileType; import org.labkey.api.util.FileUtil; +import org.labkey.api.util.JavaScriptFragment; import org.labkey.api.util.JsonUtil; import org.labkey.api.util.JunitUtil; import org.labkey.api.util.Pair; @@ -1550,7 +1551,7 @@ private static GWTDomain getDomain(String schemaName, String queryName, Integer private static Map convertDomainToApiResponse(@NotNull GWTDomain domain) { - ObjectMapper om = new ObjectMapper(); + ObjectMapper om = JsonUtil.createDefaultMapper(); _propertyService.configureObjectMapper(om, null); try { @@ -1562,13 +1563,13 @@ private static Map convertDomainToApiResponse(@NotNull GWTDomain } } - public static String convertDomainToJson(@NotNull GWTDomain domain) + public static JavaScriptFragment convertDomainToJson(@NotNull GWTDomain domain) { - ObjectMapper om = new ObjectMapper(); + ObjectMapper om = JsonUtil.createDefaultMapper(); _propertyService.configureObjectMapper(om, null); try { - return om.writeValueAsString(domain); + return JavaScriptFragment.unsafe(om.writeValueAsString(domain)); } catch (Exception e) { diff --git a/experiment/src/org/labkey/experiment/controllers/property/templateUpdate.jsp b/experiment/src/org/labkey/experiment/controllers/property/templateUpdate.jsp index f0a5f7c22b3..c4b2fce351f 100644 --- a/experiment/src/org/labkey/experiment/controllers/property/templateUpdate.jsp +++ b/experiment/src/org/labkey/experiment/controllers/property/templateUpdate.jsp @@ -18,6 +18,7 @@ <%@ page import="org.labkey.api.view.HttpView" %> <%@ page import="org.labkey.api.view.template.ClientDependencies" %> <%@ page import="org.labkey.experiment.controllers.property.PropertyController" %> +<%@ page import="org.labkey.api.util.JavaScriptFragment" %> <%@ page extends="org.labkey.api.jsp.JspBase" %> <%! @Override @@ -55,10 +56,10 @@ { var schemaName = <%= q(model.schemaName) %>; var queryName = <%= q(model.queryName) %>; - var domain = <%= text(PropertyController.convertDomainToJson(model.domain)) %>; + var domain = <%= PropertyController.convertDomainToJson(model.domain) %>; domain.schemaName = schemaName; domain.queryName = queryName; - var template = <%= text(null==model.template ? "null" : PropertyController.convertDomainToJson(model.template)) %>; + var template = <%= null==model.template ? JavaScriptFragment.NULL : PropertyController.convertDomainToJson(model.template) %>; <% if (null == model.info) { %> var templateInfo = null; <% } else { %> diff --git a/mothership/src/org/labkey/mothership/MothershipController.java b/mothership/src/org/labkey/mothership/MothershipController.java index 601fa860d61..c1ce0a2b3b5 100644 --- a/mothership/src/org/labkey/mothership/MothershipController.java +++ b/mothership/src/org/labkey/mothership/MothershipController.java @@ -73,6 +73,7 @@ import org.labkey.api.util.DateUtil; import org.labkey.api.util.GUID; import org.labkey.api.util.HtmlString; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.MothershipReport; import org.labkey.api.util.Pair; import org.labkey.api.util.URLHelper; @@ -1211,8 +1212,7 @@ public Pair toSession(Container container) try { // Capture the Core module's info to put into mothership.SoftwareRelease - ObjectMapper mapper = new ObjectMapper(); - Map parsed = mapper.readValue(getJsonMetrics(), Map.class); + Map parsed = JsonUtil.DEFAULT_MAPPER.readValue(getJsonMetrics(), Map.class); Object modulesObject = parsed.get("modules"); if (modulesObject instanceof Map modulesMap) { diff --git a/mothership/src/org/labkey/mothership/MothershipManager.java b/mothership/src/org/labkey/mothership/MothershipManager.java index f6544c06c41..694253d5716 100644 --- a/mothership/src/org/labkey/mothership/MothershipManager.java +++ b/mothership/src/org/labkey/mothership/MothershipManager.java @@ -37,6 +37,7 @@ import org.labkey.api.security.User; import org.labkey.api.util.DateUtil; import org.labkey.api.util.GUID; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.MothershipReport; import org.labkey.api.util.ReentrantLockWithName; import org.labkey.api.util.logging.LogHelper; @@ -377,7 +378,7 @@ private String getBestJson(String currentValue, String newValue, String serverSe // Verify the newValue as valid json; if it is, return it. Otherwise, return null. try { - new ObjectMapper().readTree(newValue); + JsonUtil.DEFAULT_MAPPER.readTree(newValue); return newValue; } catch (IOException e) @@ -388,7 +389,7 @@ private String getBestJson(String currentValue, String newValue, String serverSe } // Rather than overwrite the current json map, merge the new with the current. - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = JsonUtil.createDefaultMapper(); try { log.debug("Merging JSON. Old is " + currentValue.length() + " characters, new is " + newValue.length()); diff --git a/pipeline/src/org/labkey/pipeline/api/PipelineServiceImpl.java b/pipeline/src/org/labkey/pipeline/api/PipelineServiceImpl.java index 5aa9a84ed01..6f9bef4774c 100644 --- a/pipeline/src/org/labkey/pipeline/api/PipelineServiceImpl.java +++ b/pipeline/src/org/labkey/pipeline/api/PipelineServiceImpl.java @@ -67,6 +67,7 @@ import org.labkey.api.study.FolderArchiveSource; import org.labkey.api.trigger.TriggerConfiguration; import org.labkey.api.util.FileUtil; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.NetworkDrive; import org.labkey.api.util.TestContext; import org.labkey.api.util.logging.LogHelper; @@ -945,7 +946,7 @@ public String startFileAnalysis(AnalyzeForm form, @Nullable Map } ParamParser parser = PipelineJobService.get().createParamParser(); Map params = new HashMap<>(); - Map parsedMap = new ObjectMapper().readValue(form.getConfigureJson(), new TypeReference>(){}); + Map parsedMap = JsonUtil.DEFAULT_MAPPER.readValue(form.getConfigureJson(), new TypeReference>(){}); for (Map.Entry entry : parsedMap.entrySet()) { params.put(entry.getKey(), entry.getValue() == null ? null : entry.getValue().toString()); diff --git a/pipeline/src/org/labkey/pipeline/createPipelineTrigger.jsp b/pipeline/src/org/labkey/pipeline/createPipelineTrigger.jsp index 7e8fe1c068b..1c6c07cc625 100644 --- a/pipeline/src/org/labkey/pipeline/createPipelineTrigger.jsp +++ b/pipeline/src/org/labkey/pipeline/createPipelineTrigger.jsp @@ -30,6 +30,7 @@ <%@ page import="org.labkey.api.util.UniqueID" %> <%@ page import="org.labkey.api.pipeline.trigger.PipelineTriggerRegistry" %> <%@ page import="org.labkey.api.util.JsonUtil" %> +<%@ page import="org.labkey.api.util.JavaScriptFragment" %> <%@ page extends="org.labkey.api.jsp.JspBase" %> <%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %> <%! @@ -92,10 +93,10 @@
diff --git a/survey/src/org/labkey/survey/SurveyManager.java b/survey/src/org/labkey/survey/SurveyManager.java index ee762fa1e26..ceb7ceaa4b3 100644 --- a/survey/src/org/labkey/survey/SurveyManager.java +++ b/survey/src/org/labkey/survey/SurveyManager.java @@ -707,8 +707,7 @@ public MultiValuedMap load(Stream reso */ public static String validateSurveyMetadata(String metadata) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.readTree(metadata); + JsonUtil.DEFAULT_MAPPER.readTree(metadata); StringBuilder sb = new StringBuilder(); try diff --git a/visualization/src/org/labkey/visualization/VisualizationController.java b/visualization/src/org/labkey/visualization/VisualizationController.java index b89401041fc..0974b4fe1b5 100644 --- a/visualization/src/org/labkey/visualization/VisualizationController.java +++ b/visualization/src/org/labkey/visualization/VisualizationController.java @@ -91,6 +91,7 @@ import org.labkey.api.study.StudyService; import org.labkey.api.thumbnail.ThumbnailService; import org.labkey.api.thumbnail.ThumbnailService.ImageType; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.PageFlowUtil; import org.labkey.api.util.Pair; import org.labkey.api.util.ResponseHelper; @@ -1648,7 +1649,7 @@ public static class TestCase extends Assert @Test public void testJacksonBinding() throws Exception { - ObjectReader r = new ObjectMapper().reader(VisDataRequest.class) + ObjectReader r = JsonUtil.DEFAULT_MAPPER.reader(VisDataRequest.class) .without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); String measure1 = "{\"allowNullResults\":true, \"aggregate\":\"MAX\", \"alias\":\"table_column\", " + "\"inNotNullSet\":true, \"name\":\"column\", \"nsvalues\":\"whatisthis\"," + diff --git a/visualization/src/org/labkey/visualization/VisualizationServiceImpl.java b/visualization/src/org/labkey/visualization/VisualizationServiceImpl.java index 8e2c2408c69..66b0bc45616 100644 --- a/visualization/src/org/labkey/visualization/VisualizationServiceImpl.java +++ b/visualization/src/org/labkey/visualization/VisualizationServiceImpl.java @@ -35,6 +35,7 @@ import org.labkey.api.query.UserSchema; import org.labkey.api.security.User; import org.labkey.api.study.DatasetTable; +import org.labkey.api.util.JsonUtil; import org.labkey.api.util.Pair; import org.labkey.api.view.ViewContext; import org.labkey.api.visualization.SQLGenerationException; @@ -63,8 +64,7 @@ public SQLResponse getDataGenerateSQL(Container c, User user, JSONObject json) t ViewContext context = new ViewContext(); context.setUser(user); context.setContainer(c); - - ObjectReader r = new ObjectMapper().reader(VisDataRequest.class).without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + ObjectReader r = JsonUtil.DEFAULT_MAPPER.reader(VisDataRequest.class).without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); VisDataRequest vdr = r.readValue(json.toString()); vdr.setMetaDataOnly(true); @@ -85,7 +85,7 @@ public SQLResponse getDataCDSGenerateSQL(Container c, User user, JSONObject json context.setUser(user); context.setContainer(c); - ObjectReader r = new ObjectMapper().reader(VisDataRequest.class).without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + ObjectReader r = JsonUtil.DEFAULT_MAPPER.reader(VisDataRequest.class).without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); VisDataRequest vdr = r.readValue(json.toString()); vdr.setMetaDataOnly(true); diff --git a/visualization/src/org/labkey/visualization/views/chartWizard.jsp b/visualization/src/org/labkey/visualization/views/chartWizard.jsp index 9a9a3ae5910..a7509b01601 100644 --- a/visualization/src/org/labkey/visualization/views/chartWizard.jsp +++ b/visualization/src/org/labkey/visualization/views/chartWizard.jsp @@ -125,7 +125,7 @@ canEdit: canEdit, canShare: <%=canShare%>, isDeveloper: <%=isDeveloper%>, - defaultNumberFormat: eval("<%=text(numberFormatFn)%>"), + defaultNumberFormat: eval(<%=q(numberFormatFn)%>), allowEditMode: <%=allowEditMode%>, editModeURL: editUrl,