Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
d66f9eae
Commit
d66f9eae
authored
10 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Handle PGobjects when serializing JSON (e.g. raw data that contains
PostGIS geometries)
parent
610a9dde
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/middleware/format.clj
+14
-6
14 additions, 6 deletions
src/metabase/middleware/format.clj
src/metabase/util.clj
+3
-3
3 additions, 3 deletions
src/metabase/util.clj
with
17 additions
and
9 deletions
src/metabase/middleware/format.clj
+
14
−
6
View file @
d66f9eae
(
ns
metabase.middleware.format
(
:require
[
clojure.core.match
:refer
[
match
]]
cheshire.factory
(
cheshire
factory
[
generate
:refer
[
add-encoder
encode-str
]])
[
medley.core
:refer
[
filter-vals
map-vals
]]
[
metabase.util
:as
util
]))
(
declare
-format-response
)
;; # SHADY HACK
;; #
#
SHADY HACK
;; Tell the JSON middleware to use a date format that includes milliseconds
(
intern
'cheshire.factory
'default-date-format
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
)
;; # FORMAT RESPONSE MIDDLEWARE
;; ## Custom JSON encoders
(
add-encoder
org.h2.jdbc.JdbcClob
(
fn
[
clob
^
com.fasterxml.jackson.core.JsonGenerator
json-generator
]
; stringify JDBC Clobs
(
.writeString
json-generator
(
util/jdbc-clob->str
clob
))))
(
add-encoder
org.postgresql.util.PGobject
encode-str
)
; stringify Postgres binary objects (e.g. PostGIS geometries)
;; ## FORMAT RESPONSE MIDDLEWARE
(
defn
format-response
"Middleware that recurses over Clojure object before it gets converted to JSON and makes adjustments neccessary so the formatter doesn't barf.
e.g. functions and delays are stripped and H2 Clobs are converted to strings."
...
...
@@ -21,8 +30,8 @@
(
defn-
remove-fns-and-delays
"Remove values that are fns or delays from map M."
[
m
]
(
filter-vals
#
(
not
(
or
(
delay
?
%
)
(
fn
?
%
)))
(
filter-vals
#
(
not
(
or
(
fn
?
%
)
(
delay
?
%
)))
m
))
(
defn-
clob?
[
obj
]
...
...
@@ -33,5 +42,4 @@
(
map?
obj
)
(
->>
(
remove-fns-and-delays
obj
)
; recurse over all vals in the map
(
map-vals
-format-response
))
(
coll?
obj
)
(
map
-format-response
obj
)
; recurse over all items in the collection
(
clob?
obj
)
(
util/jdbc-clob->str
obj
)
:else
obj
))
This diff is collapsed.
Click to expand it.
src/metabase/util.clj
+
3
−
3
View file @
d66f9eae
...
...
@@ -107,11 +107,11 @@
(
defn
jdbc-clob->str
"Convert a `JdbcClob` to a `String`."
([
clob
]
(
^
String
[
clob
]
(
when
clob
(
if
(
string?
clob
)
clob
(
->>
(
->
(
.getCharacterStream
^
org.h2.jdbc.JdbcClob
clob
)
(
jdbc-clob->str
[]))
(
->>
(
jdbc-clob->str
(
.getCharacterStream
^
org.h2.jdbc.JdbcClob
clob
)
[])
(
interpose
"\n"
)
(
apply
str
)))))
([
^
java.io.BufferedReader
reader
acc
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment